【发布时间】:2013-08-24 15:42:22
【问题描述】:
我有一个 IIS 托管的 WCF 网络服务。它从两个消费者开始。
1) 同一解决方案中的 WinForm 测试工具,用于在 IDE 中测试 WCF 合同。
2) 使用已发布版本的 Asp.Net Web 应用程序。
可以说,一切都是开箱即用的。
随之而来的是第三个消费者,一款 Android 应用。要正确使用此功能,必须使用 JSON WebGets 和 Webinvokes 装饰 WCF 合同,并更改 WCF Web.config 以适应。
现在原来的两个消费者不再工作了。所以我需要更改 Web.config 和/或 App.configs 以获得所有三个都可以工作的配置。
首先关注 IDE。我有 WCF 服务 Web.Config 的以下服务模型部分。
<system.serviceModel>
<client>
<endpoint binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding" contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
bindingConfiguration="" name="jsonEndPoint"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="false" />
</system.serviceModel>
WinForm 测试工具 App.config 具有:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttp" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttp"
contract="CouponParking.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
</system.serviceModel>
我在配置端点方面没有经验,以上都是基于示例和猜测。
当我运行测试工具时,wcf 客户端会实例化,但对合约的调用失败:
There was no endpoint listening at http://localhost:8707/CouponParking.svc
that could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details."
内部异常是:
{"The remote server returned an error: (404) Not Found."}
[System.Net.WebException]: {"The remote server returned an error: (404) Not Found."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233079
InnerException: null
Message: "The remote server returned an error: (404) Not Found."
Source: "System"
StackTrace: " at System.Net.HttpWebRequest.GetResponse()\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)"
TargetSite: {System.Net.WebResponse GetResponse()}
如果我做错了什么,我将不胜感激。
谢谢
【问题讨论】:
-
您是否尝试在同一端点上向不同的客户端(具有不同的需求 - 即绑定)公开相同的服务?如果是这样,你不能那样做。您需要为服务的不同实现公开不同的端点。
-
另外,您能否将配置文件发布为在添加第三个客户端之前?了解它在工作时的状态以及现在的状态(当它不工作时)可能会有所帮助。
-
每个服务器端端点都有定义一个绑定 - 例如您不能拥有一个端点,既支持您的第一个和第二个客户端的
basicHttpBinding(SOAP),同时还支持 Android 客户端的webHttpBinding(REST)。为此,您需要使用两个单独的端点。
标签: c# wcf web-services