Jer*_*acs 3 c# configuration wcf wcf-binding wcf-client
我有一个WCF的web服务我在我的本地机器上测试,它给了我一个headscratcher.
我的服务配置如下:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="mex"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我的客户端配置如下:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDatroseService"
closeTimeout="00:02:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288"
maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288"
maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DatroseServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
在http://localhost/DatroseWCFService/DatroseService.svc上没有可以接受该消息的端点.这通常是由错误的地址或SOAP操作引起的.有关更多详细信息,请参阅InnerException(如果存在).
...然而,如果我浏览到我获得服务屏幕的位置,那么它似乎已正确设置.
我确定这与我的端点配置有关,但我无法弄清楚它们应该是什么样子.这里有一些帮助.
UPDATE whups我输错了错误信息.现在已经修复了.
根据我认为在这些响应中建议的更新2我已将服务器配置更改为:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="/svc"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
和我的客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDatroseService"
closeTimeout="00:02:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288"
maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="524288" maxArrayLength="524288"
maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc/svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DatroseServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我现在得到一个400(错误的请求)错误.我不确定这是前进还是后退.我是否创建了一个新问题,还是让我清楚了解下一个问题?
更新3
根据niao的建议,我更改为服务器配置:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" behaviorConfiguration="DatroseServiceBehavior">
<endpoint contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" binding="basicHttpBinding" address="http://localhost/DatroseWCFService/DatroseService.svc"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
...但是,当我浏览这个地址时,我得到了一个黄色的死亡屏幕:
'/ DatroseWCFService'应用程序中的服务器错误.
当'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled'在配置中设置为true时,端点需要指定相对地址.如果要在端点上指定相对侦听URI,则地址可以是绝对的.要解决此问题,请为端点"http://localhost/DatroseWCFService/DatroseService.svc"指定相对uri.
......所以,我试着把它变成一条相对的路径:
<endpoint
address="localhost/DatroseWCFService/DatroseService.svc"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
Run Code Online (Sandbox Code Playgroud)
...但在发布之后,我收到404错误.客户端端点配置如下:
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
Run Code Online (Sandbox Code Playgroud)
更新4 根据marc_s的建议,我从客户端删除了绑定配置,所以我的配置如下所示:
<system.serviceModel>
<client>
<endpoint address="http://localhost/DatroseWCFService/DatroseService.svc" behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
contract="DatroseWCFService.IDatroseService" name="BasicHttpBinding_IDatroseService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DatroseServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我的服务器配置如下所示:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" behaviorConfiguration="DatroseServiceBehavior">
<endpoint contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" binding="basicHttpBinding" address=""/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true" httpHelpPageEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我不再收到404错误.
但是,我确实得到了一个400(ProtocolException,Bad Request),没有任何关于它得到的信息或为什么它不好的信息.我希望我已经超越了端点问题,进入了全新的服务配置空间.
更新5
每个请求,我的服务的"骨架"(我假设接口会这样做?):
[ServiceContract]
public interface IDatroseService
{
[OperationContract]
bool SubmitPayableTransaction(List<InvoiceItem> invoices);
[OperationContract]
Dictionary<string, bool> ValidateAccounts(List<string> accounts);
[OperationContract]
Dictionary<string, int> GetVendor1099Types(List<string> vendors);
[OperationContract]
Dictionary<string, string> GetPaymentTerms(List<string> vendors);
}
Run Code Online (Sandbox Code Playgroud)
mar*_*c_s 16
所以我假设您的服务是在IIS内托管的,对吧?
那么你的*.svc
生活基本上定义了服务地址的虚拟目录- 这个地址是否正确?
另外:您mex
在服务端点上有"相对"地址
<endpoint
address="mex"
Run Code Online (Sandbox Code Playgroud)
(我认为这是一个非常糟糕的主意 - MEX代表元数据交换,我不会将该地址用于常规服务端点!它只是违反了最低惊喜原则 - 如果端点被调用 MEX
,我希望它是一个元数据交换端点 - 不是常规服务端点...)
无论如何 - 使用该常规地址,您的完整服务地址将变为:
http://yourserver/DatroseWCFService/DatroseService.svc/mex
Run Code Online (Sandbox Code Playgroud)
如果您在该地址上拨打您的服务怎么办?您会收到回复吗?
更新:不确定您是如何尝试测试的.这是一个SOAP Web服务 - 您将在浏览器中看到服务的"登录页面"("帮助"页面),但是要测试服务本身,您需要使用支持SOAP的测试工具(如WCF测试)客户端或SoapUI) - 您无法通过浏览其Web地址来测试SOAP Web服务.
(好吧,所以你通过从测试应用程序调用服务来测试它 - 这应该绝对有效!)
更新#2:因为您在IIS中托管它(对吗?),您的服务地址基本上由*.svc文件所在的虚拟目录定义.所以我的下一次尝试是:只需将该地址作为您的服务地址即可.
将服务端配置更改为:
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="" <!-- define nothing here - just let the *.svc file determine your service address -->
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
Run Code Online (Sandbox Code Playgroud)
和您的客户端配置:
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService"
contract="DatroseWCFService.IDatroseService" />
Run Code Online (Sandbox Code Playgroud)
那样有用吗??
下一次尝试是使用没有bindingConfiguration=
值的客户端配置- 因为这也是你在服务器上所做的事情 - 只是绝对basicHttpBinding
没有任何修改的裸机- 这有用吗?
归档时间: |
|
查看次数: |
38630 次 |
最近记录: |