Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

c# - One WCF service – two clients; One client does not work

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 ActionReplyAction. 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:

  1. 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:oolboxLijosServiceAppNewServiceRestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" />
  <xsd:import schemaLocation="C:oolboxLijosServiceAppNewServiceRestaurantData.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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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

  2. Use Tracing as mentioned in How to turn on WCF tracing?

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

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...