一个WCF服务 - 两个客户端;一个客户端不能正常工作客户端、不能正常、两个、工作

2023-09-02 02:03:31 作者:— 剧终 —

我有一个WCF服务和两个控制台应用程序的客户端。

服务:该服务code都使用WCSF蓝色工具WSDL联系人创建

客户端1:此客户端使用由浏览SVC文件获得的WSDL。这个浏览WSDL文件是从合同的WSDL文件稍有不同。

客户端2:使用原始WSDL合约创建该客户端

Cleint1工作正常。客户端2不工作。什么都可能是潜在的问题?

App.config的两个客户端文件看起来相似 - 只是名称的变化。我认为,这个问题将在客户端的C#code产生的 - 最有可能在操作 - ReplyAction 。还有什么需要在这里纠正?

一个显着的区别是在行动和ReplyAction

客户端1:

  

行动=金塔:lijo:演示:multiplyservice:计算:V1 / ICalculationService / GetMultiplied,ReplyAction =金塔:lijo:演示:multiplyservice:计算:V1 / ICalculationService / GetMultipliedRe+               sponse

客户端2:

  

行动=金塔:lijo:演示:multiplyservice:计算:V1:getMultipliedIn,ReplyAction =*

跟踪消息

  

与行动瓮:lijo:演示:multiplyservice:计算:V1:getMultipliedIn的消息无法在接收端进行处理,由于ContractFilter不匹配的EndpointDispatcher。这可能是因为一个合同不匹配或发送方和接收方之间的结合/安全不匹配(发送者和接收者之间不匹配的操作)。检查发送者和接收者有相同的合同,相同的绑定(包括安全要求,如信息,运输,无)。

修改

这可以通过改变操作和ReplyAction如下进行修正(从服务抄了一遍)。

  [System.ServiceModel.OperationContractAttribute(行动=金塔:lijo:演示:multiplyservice:计算:V1 / ICalculationService / getMultiplied,ReplyAction =金塔:lijo:演示:multiplyservice:计算:V1 / ICalculationService / getMultipliedRe+
        sponse)]
 
java 怎么调用.net wcf服务,怎么生成客户端代码

注:确保在服务外壳是否正确是很重要的(即getMultiplied不GetMultiplied)

从服务复制是不是一个好的选择,但它的工作原理。什么是正确的行动和ReplyAction?

另外,能否请你指出如何修改WSDL,以使ReplyAction将在生成的客户端代理正确?这是必不可少的一部分,回答以纪念它。

WCF:行动,星号和元数据

  

WsdlExporter,其用于元数据发布,忽略操作以星号的动作(动作都与ReplyAction)。

从 MSDN -ReplyAction物业

  

指定在服务星号指示WCF不答复操作添加到该消息,如果你是直接对节目的消息时非常有用。

参考

WCF元数据丢失的操作

RestaurantData.xsd

< XML版本=1.0编码=UTF-8&GT?;  < XS:模式ID =RestaurantData的targetNamespace =金塔:lijo:演示:multiplyservice:数据:V1     将elementFormDefault =合格的xmlns =金塔:lijo:演示:multiplyservice:数据:V1     的xmlns:mstns =金塔:lijo:演示:multiplyservice:数据:V1的xmlns:XS =htt​​p://www.w3.org/2001/XMLSchema>   < XS:复杂类型的名称=multipliedResult>   < XS:序列>   < XS:元素的名称=resultNumber类型=XS:INT/>    < / XS:序列>    < / XS:复杂类型>   < / XS:模式>

原合同的WSDL

<定义的xmlns:import0 =金塔:lijo:演示:multiplyservice:消息:V1的xmlns:XSD = http://www.w3.org/2001/XMLSchema的xmlns:import1 =金塔:lijo:演示:multiplyservice:数据:V1的xmlns:TNS =金塔:lijo:演示:multiplyservice:计算:V1的xmlns:肥皂=htt​​p://schemas.xmlsoap.org/wsdl/soap/的xmlns:SOAP12 =htt​​p://schemas.xmlsoap.org/wsdl/soap12/NAME =CalculationService的targetNamespace =金塔:lijo:演示:multiplyservice:计算:V1的xmlns =http://schemas.xmlsoap.org/wsdl/>  < WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>  <类型>  < XSD:架构>   < XSD:导入的schemaLocation =C:工具箱 LijosServiceApp NewService RestaurantMessages.xsd命名空间=金塔:lijo:演示:multiplyservice:消息:V1/>   < XSD:导入的schemaLocation =C:工具箱 LijosServiceApp NewService RestaurantData.xsd命名空间=金塔:lijo:演示:multiplyservice:数据:V1/> < / XSD:模式> < /类型> <消息名称=getMultipliedIn> < WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//> <部分名称=参数元素=import0:getMultiplied/> < /消息> <消息名称=getMultipliedOut> < WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//> <部分名称=参数元素=import0:getMultipliedResponse/> < /消息> <端口类型名称=CalculationServiceInterface> < WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//> <操作NAME =getMultiplied>   < WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>   <输入消息=TNS:getMultipliedIn/>   <输出消息=TNS:getMultipliedOut/> < /运转> < /端口类型> <绑定名称=BasicHttpBinding_CalculationServiceInterfaceTYPE =TNS:CalculationServiceInterface> <肥皂:绑定传输=htt​​p://schemas.xmlsoap.org/soap/http/> <操作NAME =getMultiplied>   <肥皂:操作的soapAction =金塔:lijo:演示:multiplyservice:计算:V1:getMultipliedIn的风格=文件/>   <输入>     <肥皂:身体使用=文字/>   < /输入>   <输出>     <肥皂:身体使用=文字/>   &所述; /输出GT;  < /运转>  < /装订>  <服务名称=CalculationServicePort>  <端口名称=CalculationServicePort绑定=TNS:BasicHttpBinding_CalculationServiceInterface>   <肥皂:地址位置=HTTP://本地主机/ CalculationService/>  < /端口>  < /服务>  < /定义>

解决方案

我想它了。为他人谋取利益我在这里会解释。

而在此之前,请参考答案400错误的请求例外:小数据了解一些调试想法简单的SOAP WCF服务

这是由于 格式的SOAP动作选项WCSF蓝工具。

我曾用格式皂操作,而产生使用WCSF蓝色的code。但是,当客户端,我没有使用的工具。这不匹配是关键问题。

格式香皂操作强制SOAP动作(动作和 ReplyAction )应用到每个经营合同遵循的的标准WCF格式的

 <空间> /<服务> /<动作> [回应]
 

如果我有对客户端没有控制,我不应该在WCSF蓝工具使用的格式SOAP操作选项。

请参阅Service作品从wcfTestClient,但未能在控制台应用程序工作的例子。

[尽管如此,我有一个问题 - 如果我无法控制的客户端仍然需要使用 ReplyAction ?这将是在XML格式在这种情况下也就是在客户端和服务所使用的URI? ]

常规调试思路:

确保良好的服务是通过使用wcfTestClient(类型wcfTestClient在VS的命令提示符启动)

使用跟踪如如何打开WCF的跟踪?

验证配置值在web.config中/的app.config并没有在output.config(在自动生成使用工具)

确认你是指正确的WSDL(它是从运行服务的本地文件或URL?)

确定WSDL可以通过浏览SVC文件中查看。元数据是启用

检查它是否在服务的地址相对路径或绝对路径

I have one WCF service and two console app clients.

Service: The service code is created from a wsdl contact using WCSF Blue tool.

Client 1: This client is using wsdl that is obtained by browsing the svc file. This browsed wsdl file is slightly different from the contract wsdl file.

Client 2: This client is created using the original wsdl contract.

Cleint1 is working fine. Client 2 is not working. What all could be potential issues?

App.Config file of both the clients look similar – only the name changes. I think, the problem will be in the client C# code generated – most probably in the Action – ReplyAction. What need to be corrected here?

One noticeable difference is in Action and ReplyAction

Client 1:

Action="urn:lijo:demos:multiplyservice:calculation:v1/ICalculationService/GetMultiplied", ReplyAction="urn:lijo:demos:multiplyservice:calculation:v1/ICalculationService/GetMultipliedRe" + "sponse"

Client 2:

Action="urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn", ReplyAction="*"

Trace Message

The message with Action 'urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

EDIT

This can be corrected by changing the Action and ReplyAction as below (Copied it from Service).

  [System.ServiceModel.OperationContractAttribute(Action = "urn:lijo:demos:multiplyservice:calculation:v1/ICalculationService/getMultiplied", ReplyAction = "urn:lijo:demos:multiplyservice:calculation:v1/ICalculationService/getMultipliedRe" +
        "sponse")]

Note: It is important to ensure that the casing in the service is correct (i.e, getMultiplied not GetMultiplied)

Copying from the service is not a good option, though it works. What would be the correct Action and ReplyAction?

Also, Can you please point out how to modify the wsdl so that the ReplyAction will be correct in the generated client proxy? That is the essential part to mark it as answered.

WCF: Actions, Asterisk and Metadata

WsdlExporter, which is used for metadata publishing, ignores operations with asterisk actions (both Action and ReplyAction).

From MSDN -ReplyAction Property

Specifying an asterisk in the service instructs WCF not to add a reply action to the message, which is useful if you are programming against messages directly.

REFERENCES:

WCF metadata missing operations

RestaurantData.xsd

 <?xml version="1.0" encoding="utf-8" ?>
 <xs:schema id="RestaurantData" targetNamespace="urn:lijo:demos:multiplyservice:data:v1"
    elementFormDefault="qualified" xmlns="urn:lijo:demos:multiplyservice:data:v1"
    xmlns:mstns="urn:lijo:demos:multiplyservice:data:v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="multipliedResult">
  <xs:sequence>
  <xs:element name="resultNumber" type="xs:int" />
   </xs:sequence>
   </xs:complexType>

  </xs:schema>

Original Contract wsdl

 <definitions xmlns:import0="urn:lijo:demos:multiplyservice:messages:v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import1="urn:lijo:demos:multiplyservice:data:v1" xmlns:tns="urn:lijo:demos:multiplyservice:calculation:v1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="CalculationService" targetNamespace="urn:lijo:demos:multiplyservice:calculation:v1" xmlns="http://schemas.xmlsoap.org/wsdl/">

 <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
 <types>
 <xsd:schema>
  <xsd:import schemaLocation="C:toolboxLijosServiceAppNewServiceRestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" />
  <xsd:import schemaLocation="C:toolboxLijosServiceAppNewServiceRestaurantData.xsd" namespace="urn:lijo:demos:multiplyservice:data:v1" />
</xsd:schema>
</types>
<message name="getMultipliedIn">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<part name="parameters" element="import0:getMultiplied" />
</message>
<message name="getMultipliedOut">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<part name="parameters" element="import0:getMultipliedResponse" />
</message>
<portType name="CalculationServiceInterface">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<operation name="getMultiplied">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <input message="tns:getMultipliedIn" />
  <output message="tns:getMultipliedOut" />
</operation>
</portType>
<binding name="BasicHttpBinding_CalculationServiceInterface" type="tns:CalculationServiceInterface">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getMultiplied">
  <soap:operation soapAction="urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn" style="document" />
  <input>
    <soap:body use="literal" />
  </input>
  <output>
    <soap:body use="literal" />
  </output>
 </operation>
 </binding>
 <service name="CalculationServicePort">
 <port name="CalculationServicePort" binding="tns:BasicHttpBinding_CalculationServiceInterface">
  <soap:address location="http://localhost/CalculationService" />
 </port>
 </service>
 </definitions>

解决方案

I figured it out. For the benefit of others I will explain it here.

Before that please refer answer to the 400 Bad Request Exception: Simple SOAP WCF service with small data for some debugging ideas.

This due to Format SOAP Action option in WCSF Blue tool.

I have used "Format Soap Actions" while generating the code using WCSF Blue. But while client, I did not use the tool. That mismatch is the key issue.

Format Soap Actions force the SOAP actions (Action and ReplyAction) applied to each operation contract follow the standard WCF format:

  <namespace>/<service>/<operation>[Response] 

If I have no control over the client, I should not use Format SOAP Action option in WCSF Blue Tool.

Please refer Service works from wcfTestClient but fails in Console Application for a working example.

[Still I have a question - what if I have no control over the client still need to use ReplyAction? What will be the URI in xml format in such scenario that is to be used in the client and service ? ]

General Debugging Ideas:

Ensure that the service is good by using wcfTestClient (type wcfTestClient in VS command prompt to launch)

Use Tracing as mentioned in How to turn on WCF Tracing?

Verify that the configuration values are in web.config/app.config and not in output.config (in case of auto generation using tools)

Verify that you are referring proper wsdl (is it local file or url from running service?)

Verify that the wsdl can be viewed by browsing the svc file. Metadata is enabled

Check whether it is relative path or absolute path in the "address" in the service