Server did not recognize the value of HTTP Header SOAPAction initiate - c#

i have a simple web method. when i call it i get the below error.
Server did not recognize the value of HTTP Header SOAPAction initiate.
we call the webmethod from java client and we add the below code to the header.
addRequestHeader("SOAPAction", "initiate");
how to add it to the header in the server code (C#)?

I've decided to post my own answer here because I've lost a few hours on this and I think that, although the accepted answer of this other question (http://stackoverflow.com/questions/352174/server-did-not-recognize-the-value-of-http-header-soapaction/14084341#14084341) is very good and pointed me in the right direction (yes, it got a voteup), it was not detailed enough to explain what was wrong with my application, at least in my case.
I'm running a BPEL module in OpenESB 2.2 and the Test Case of my Composite Application was failing with the following error:
Caused by: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
After doing some research I've noticed that the external WSDL has all the clues we need to fix this problem, e.g., I'm using the following web service to validate a credit card number through a orchestration of Web Services: http://www.webservicex.net/CreditCard.asmx?WSDL
If you check the
<wsdl:binding name="CCCheckerSoap" type="tns:CCCheckerSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ValidateCardNumber">
<soap:operation soapAction="http://www.webservicex.net/ValidateCardNumber" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
...
But, once you create the Composite Application and build the project with the BPEL that invokes this external WSDL service, for some reason (bug?), the XML of the Composite Application Service Assembly (CASA) binding is generated with an empty soapAction parameter:
<binding name="casaBinding1" type="ns:CCCheckerSoap">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="ValidateCardNumber">
<soap:operation soapAction="" style="document"/>
<input>
<soap:body use="literal"/>
</input>
Once you copy the proper soapAction (http://www.webservicex.net/ValidateCardNumber) into this parameter, the application's Test Case will correctly and return the expected Soap response.
<soap:operation soapAction="http://www.webservicex.net/ValidateCardNumber" style="document"/>
So, it's a more specific solution that I decided to document based on the information found in this blog post: http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/.
It means (at least in my case) that you are accessing a web service
with SOAP and passing a SOAPAction parameter in the HTTP request that
does not match what the service is expecting.

Related

.Net Core 3.1 importing WSDL Errors - How to work around?

I am trying to migrate some server code from .Net 4.7 to .Net Core 3.1 so we can run on a Linux host.
There are two connected services using SOAP. One has ported with zero changes but other has errors when importing using the WSDL file:
http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php?wsdl
I'm not a SOAP expert and have only ever used the code generated by importing WSDL files so the errors don't mean a lot to me.
Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: wsdl:definitions[#targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[#name='IndividualServiceHttpPost']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:service[#name='IndividualService']/wsdl:port[#name='IndividualServiceHttpPost']
Cannot import wsdl:binding
Detail: The required WSDL extension element 'binding' from namespace 'http://schemas.xmlsoap.org/wsdl/http/' was not handled.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[#name='IndividualServiceHttpPost']
Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[#name='IndividualServiceHttpGet']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:service[#name='IndividualService']/wsdl:port[#name='IndividualServiceHttpGet']
Cannot import wsdl:binding
Detail: The required WSDL extension element 'binding' from namespace 'http://schemas.xmlsoap.org/wsdl/http/' was not handled.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[#name='IndividualServiceHttpGet']
To simplify debugging I created simple command line apps, one for .Net 4.7 and the other Core 3.1.
Importing worked perfectly for the .Net 4.7 and I can call the service (as expected).
Importing for Core 3.1 gives the errors as above and when calling the client initialization it returns an error of:
Client.Channel = 'Client.Channel' threw an exception of type 'System.ServiceModel.CommunicationObjectFaultedException'
I get the same errors when importing using svcutil.exe manually.
After 3 days Googling I am no further on as each problem seems to be different and none of the solutions work.
Would someone be kind enough to explain what these errors actually mean (I'm not a SOAP expert) and, if possible, what I sort of things I need to do to work around them?
Download the WSDL to a file and remove the unsupported GET and POST bindings manually by removing the corresponding wsdl:binding and wsdl:port elements. You can then use the tools (dotnet-svcutil or Visual Studio / IDEs) to generate the client code (Service Reference).
--- a/service.wsdl
+++ b/service.wsdl
## -286,37 +286,6 ##
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="IndividualServiceHttpGet" type="tns:IndividualServiceHttpGet">
- <http:binding verb="GET" />
- <wsdl:operation name="SearchByLastNameAndDateOfBirth">
- <http:operation location="/SearchByLastNameAndDateOfBirth" />
- <wsdl:input>
- <http:urlEncoded />
- </wsdl:input>
- <wsdl:output>
- <mime:mimeXml part="Body" />
- </wsdl:output>
- </wsdl:operation>
- <wsdl:operation name="SearchByDrivingLicenceNumber">
- <http:operation location="/SearchByDrivingLicenceNumber" />
- <wsdl:input>
- <http:urlEncoded />
- </wsdl:input>
- <wsdl:output>
- <mime:mimeXml part="Body" />
- </wsdl:output>
- </wsdl:operation>
- <wsdl:operation name="Get">
- <http:operation location="/Get" />
- <wsdl:input>
- <http:urlEncoded />
- </wsdl:input>
- <wsdl:output>
- <mime:mimeXml part="Body" />
- </wsdl:output>
- </wsdl:operation>
- </wsdl:binding>
- <wsdl:binding name="IndividualServiceHttpPost" type="tns:IndividualServiceHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="SearchByLastNameAndDateOfBirth">
<http:operation location="/SearchByLastNameAndDateOfBirth" />
## -354,11 +323,5 ##
<wsdl:port name="IndividualServiceSoap12" binding="tns:IndividualServiceSoap12">
<soap12:address location="http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php" />
</wsdl:port>
- <wsdl:port name="IndividualServiceHttpGet" binding="tns:IndividualServiceHttpGet">
- <http:address location="http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php" />
- </wsdl:port>
- <wsdl:port name="IndividualServiceHttpPost" binding="tns:IndividualServiceHttpPost">
- <http:address location="http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php" />
- </wsdl:port>
</wsdl:service>
</wsdl:definitions>
I face similar problem afterwards I utilize "svcutil" and created a batch file with below command
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\svcutil.exe" <your service address/url like http://localhost:*****/***/**/***** > /o:"<name of class file to be created>.cs" /r:"..\..\<Any reference assembly if any otherwise leave this>" /n:*,<targetNamespace> /ct:<collectionType:<type> like System.Collections.Generic.List`1>
for more information on svcutil go to dev command of VS and run command: svcutil/?

Error when try to create Service Reference in VS2013 with fault elements from third party WSDL

I am creating a WCF Client in VS 2013 using a supplied third party WSDL for a web service - most likely running on Java.
Running svcutil on the raw WSDL gives me an error similar to this:
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType:
//wsdl:definitions[#targetNamespace='<ns>']/wsdl:portType[#name='xxxPort']
XPath to Error Source:
//wsdl:definitions[#targetNamespace='<ns>']/wsdl:binding[#name='xxxPortSoap11']
Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding:
//wsdl:definitions[#targetNamespace='<ns>']/wsdl:binding[#name='xxxPortSoap11']
XPath to Error Source:
//wsdl:definitions[#targetNamespace='<ns>']/wsdl:service[#name='xxxPortService']/wsdl:port[#name='xxxPortSoap11']
Generating files...
Warning: No code was generated. ...
In order to get the Service Reference working (or svcutil running without errors) I have to comment out the fault definitions in the port and bindings. I can live with that (as I have made a MessageInspector to pull out errors from the various detail elements), but want to get it working properly.
Simplifying the WSDL to only show the elements that give me problems gives:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
xmlns:tns="http://www.example.com/data/common/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:sch0="http://www.example.com/data/common/"
targetNamespace="http://www.example.com/data/common/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns1="http://www.example.com/data/common/"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="www.example.com/data/common/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType xmlns="http://www.w3.org/2001/XMLSchema" name="BusinessErrorType">
<xsd:sequence xmlns="http://www.w3.org/2001/XMLSchema">
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema"
name="Error" maxOccurs="unbounded" type="string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element xmlns="http://www.w3.org/2001/XMLSchema"
name="BusinessErrorFault" type="tns1:BusinessErrorType" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="BusinessErrorFault">
<wsdl:part name="BusinessErrorFault" element="sch0:BusinessErrorFault" />
</wsdl:message>
<wsdl:portType name="ViewMessagesPort">
<wsdl:operation name="BusinessError">
<wsdl:fault name="BusinessErrorFault" message="sch0:BusinessErrorFault" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ViewMessagesPortSoap11" type="sch0:ViewMessagesPort">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="BusinessError">
<soap:operation soapAction="" />
<wsdl:fault name="BusinessErrorFault">
<soap:fault use="literal" name="BusinessErrorFault" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ViewMessagesPortService">
<wsdl:port name="ViewMessagesPortSoap11" binding="sch0:ViewMessagesPortSoap11">
<soap:address location="https://www.example.com/ws/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I have looked at many SO questions and other places on the net including Scott Hanselman's breaking the rules with no joy.
Hopefully it is something blindingly obvious ... I gratefully await any answers from across the pond as I wend my way home in the UK.
UPDATE
Passing the above WSDL through https://www.wsdl-analyzer.com/ gives an error on the binding:
Style: Unknown [Warn!]
Could not detect the 'use' for the operations of binding ViewMessagesPortSoap11
I'm still none the wiser.
The WSDL you published above has an issue that there is no schema with targetNamespace of "http://www.example.com/data/common/" which is what expected by the sch0:BusinessErrorFault element. I assume this may be because you did not provide the full WSDL so I changed the targetNamespace of the schema to it. The next error if this this operation:
<wsdl:operation name="BusinessError">
<wsdl:fault name="BusinessErrorFault" message="sch0:BusinessErrorFault" />
</wsdl:operation>
has no input or output but just fault, which does not make since.
I guess this might also be because you simplified the WSDL so please publish the full one if you get more errors.

Consuming java web service through .net - data inconsistence

I have a Java project ( a voting system ) in which I implemented a web service.
My getResults method returns a String[]. If the voting is done the method returns the array populated with 'Item 1 - 2 votes, Item 2 - 3 Votes...'. If it isn't, it returns the array with a single string saying that voting is still on.
The problem is that if i call getResults from within my java application it works as expected but if i call it from my webservice it always returns that the voting is still on and never the results.
I'm consuming this web service through a c# console application is visual studio.
I'm pretty new to web services so let me ask this. When I instantiate my service like this:
ServerService ss = new ServerService();
Does it create a new instance of my class Server() in my Java application or is it just a way to connect to my current instance?
Well I hope I've explained my problem well and hope you can help me.
Thanks and merry xmas :)
Edit:
this is the method that is accessed by the web service
public String[] getResults() throws RemoteException {
if (ended) {
return results.toArray(new String[results.size()]);
} else {
ArrayList<String> temp = new ArrayList<String>();
temp.add("Voting is still on");
return temp.toArray(new String[temp.size()]);
}
}
Edit 2:
WSDL:
<wsdl:definitions targetNamespace="http://backend.ve"
xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://backend.ve" xmlns:intf="http://backend.ve" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://backend.ve" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getResults">
<complexType/>
</element>
<element name="getResultsResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="getResultsReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getResultsRequest">
<wsdl:part element="impl:getResults" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getResultsResponse">
<wsdl:part element="impl:getResultsResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="Server">
<wsdl:operation name="getResults">
<wsdl:input message="impl:getResultsRequest" name="getResultsRequest">
</wsdl:input>
<wsdl:output message="impl:getResultsResponse" name="getResultsResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServerSoapBinding" type="impl:Server">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getResults">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getResultsRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getResultsResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ServerService">
<wsdl:port binding="impl:ServerSoapBinding" name="Server">
<wsdlsoap:address location="http://localhost:8080/VE/services/Server"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
C#:
namespace WSTest
{
class Program
{
static void Main(string[] args)
{
ServerService ss = new ServerService();
foreach (String s in ss.getResults())
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}
}
It does only instantiate a C# proxy for your service - an automatically generated class by .NET with all the behind-the-scenes code to manage communication with your service.
I would advice you to test your service with a tool like SoapUI before trying to integrate it with .NET and see if you have the same problem.
I am not able to figure out the exact issue in your code, but here are some pointers which will help you to sort it out.
Your method is not returning the string, see WSDL:
<wsdl:operation name="getResults">
<wsdl:input message="impl:getResultsRequest" name="getResultsRequest">
</wsdl:input>
<wsdl:output message="impl:getResultsResponse" name="getResultsResponse">
</wsdl:output>
</wsdl:operation>
But you are expecting string as output in your C# code.
2 . You need to create two objects at C# end namely : getResultsRequest and getResultsResponse
I know you are getting same error through Eclipse, but since your service works fine when you call it from Java client. So your service logic is correct. Now only place where problem might occur is the communication between your service and client.
So my suggested C# code would be:
namespace WSTest
{
class Program
{
static void Main(string[] args)
{
ServerService ss = new ServerService();
getResultRequest request = new getResultRequest();
getResultResponse response = new getResultResponse();
response = ss.getResultResponse(request);
// Do something with response.
Console.ReadLine();
}
}
}

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 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:\toolbox\LijosServiceApp\NewService\RestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" />
<xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantData.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
You are right that there is an issue in ReplyAction. When ReplyAction is set to "*" makes WCF to ignore that operation. Correct the ReplyAction to your operation contract will work.
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/41f5fe72-3ab3-4741-867e-a93119fe62aa

How to add custom soap headers or use username auth under http?

I am trying to modify and add custom headers to a soap message in the BeforeSendRequest method like this:
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
MessageHeader header = MessageHeader.CreateHeader("name", "http://myname", "Oscar");
request.Headers.Add(header);
return null;
}
Everything is ok at this point, the header is added in the soap headers like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="51efbfdb-2187-45b9-81fc-6a38815d5bed" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">d1351a78-a53a-4d32-ad35-fca6d4262adf</ActivityId>
<name xmlns="http://myname">Oscar</name>
</s:Header>
The problem is that I want to add something bigger in the headers and the final result has to be like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="51efbfdb-2187-45b9-81fc-6a38815d5bed" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">d1351a78-a53a-4d32-ad35-fca6d4262adf</ActivityId>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">username</wsse:Username>
<wsse:Password xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</s:Header>
Is there a way to achieve this?
PS. Please guys :-) do not criticize me, I am in the following situation:
When adding this username and password auth, you need to be over https, the problem is that this Java based webservice which I am trying to communicate is under http and I think it is not compliant because according to the 3rd link "It is considered bad practice to pass credentials over an unsecured connection" but they solved it adding the headers in the config file (something I did without success).
I read these links too and tried them. Also when doing things from links 1 and 2, I got a kind of exception in Visual Studio which says something like "It is expected https and not http" that's why I am trying MessageInspectors using BeforeSendRequest method.
Configure WCF for WS-Security with Username over https
http://www.west-wind.com/weblog/posts/2007/Dec/09/Tracing-WCF-Messages
http://www.fransson.net/blog/credentials-over-plain-http-with-wcf/
ClearUsernameBinding is the solution
The 3rd parameter of CreateHeader is an object. By default this object is serialized using the DataContractSerializer so if you create a data contract that models the header structure you can pass an instance as the 3rd parameter and it will create the header you want
I had the same problem, though my service was https. And it should be a configuration matter, you shouldn't need to handle this manually.
Anyway, you don't have to use the MessageInspectors using BeforeSendRequest.
You should try and change the config generated code adding some security configuration.
WCF will then create what headers you need. Then in code add the credentials and you should be ok.
I imagine that the generated proxy is creating you a customBinding or basicHttpBinding.
basicHttpBinding though not supporting the WS-Security specifications, so you should change this either to custom or wsHttpBinding. You can play with and find the correct configuration to gain the desired results.
What I added was "Sample config syntax":
<customBinding>
<binding name="MessageServerBinding">
<security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<secureConversationBootstrap />
</security>
........
</binding>
</customBinding>
This is a sample configuration, e.g. you might not need to include a timestamp, or you could need a Nonce which if I remember correctly needs some more effore, not much though.
For check this discussion: WCF: Adding Nonce to UsernameToken
Hope this helps.

Categories

Resources