【发布时间】:2014-03-21 12:14:05
【问题描述】:
我创建了一个新的测试 WCF 应用程序。当我在 Visual Studio 中运行解决方案时,它可以使用带有 WCF 测试客户端的 Simple GetData 方法运行良好。但是,我现在想将服务引用添加到外部 WCF 服务,以便我可以从该 Web 服务与其对话。所以我 Service1 的界面现在看起来像:
public interface IService1 : MyExternalService
然后在我的服务类上,我有简单的 GetData,我可以点击实现接口,我看到创建的外部 Web 服务的所有方法:
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public string ExternalMethod1(string a, string b)
{
throw new NotImplementedException();
}
//etc
但是,如果我尝试使用 WCF 测试客户端运行它 - 我会收到以下错误消息 - Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
在我包含外部服务参考后,它更新了我的 web.config 如下(注意一些实际的 url 已清理)
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IExternalService">
<security>
<message clientCredentialType="Certificate" />
</security>
</binding>
<binding name="WSHttpBinding_IExternalService1">
<security>
<message clientCredentialType="Certificate" negotiateServiceCredential="false"
algorithmSuite="Basic128" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://service.com/ExternalService/ExternalService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExternalService"
contract="ExternalService.IExternalService" name="WSHttpBinding_IExternalService">
<identity>
<dns value="service.com" />
</identity>
</endpoint>
<endpoint address="http://service.com/ExternalService/ExternalService.svc/Java"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExternalService1"
contract="ExternalService.IExternalService" name="WSHttpBinding_IExternalService1">
<identity>
<dns value="service.com" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
【问题讨论】:
标签: c# .net web-services wcf visual-studio