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

[SoapRpcMethod(Action = "http://cyberindigo/TempWebService/InsertXML",
RequestNamespace = "http://cyberindigo/TempWebService/Request",
RequestElementName = "InsertXMLRequest",
ResponseNamespace = "http://cyberindigo/TempWebService/Response",
ResponseElementName = "InsertXMLResponse",
Use = System.Web.Services.Description.SoapBindingUse.Literal)]
[WebMethod]
public string InsertXML(string Jobs)
{
return "Hi";
}
The Problem when I am accessing it using XMLHttpRequest it gives following error
Server did not recognize the value of HTTP Header SOAPAction: http://Cyberindigo/TempWebService/InsertXML

The source of the next part of this post is:
http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/
(since the OP didn't want to give attribution, and thanks to Peter)
Please note that bakert is the original author of the text, not the OP.
Seeing as nowhere on the internet can I find an explanation of this error I thought I’d share the fruits of my long search for this bug.
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.
I got in a pickle because we moved a web service from one server to another and thus I changed the “namespace” (don’t get confused between web service namespaces and .net namespaces) in the calling C# file to match the new server. But the server doesn’t care about the actual web reality of http://yournamespace.com/blah it only cares that you send it what you have said you are expecting on the server. It doesn’t care if there’s actually anything there or not.
So basically the web service was moved from http://foo.com/servicename to http://bar.com/servicename but the “namespace” of the web service stayed as http://foo.com/servicename because no one changed it.
And that only took about 4 hours to work out!
If you’re having a similar problem but can’t work what I’m saying here, feel free to mail me on bakert+web#gmail.com – I wouldn’t wish my four hours on anyone!

While calling the .asmx / wcf web service please take care of below points:
The namespace is case sensitive,the SOAP request MUST be sent with the same namespace with which the WebService is declared.
e.g. For the WebService declared as below
[WebService(Namespace = "http://MyDomain.com/TestService")]
public class FooClass : System.Web.Services.WebService
{
[WebMethod]
public bool Foo( string name)
{
......
}
}
The SOAP request must maintain the same case for namespace while calling.Sometime we overlook the case sensitivity.
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Foo xmlns="http://MyDomain.com/TestService">
<name>string</name>
</Foo>
</soap:Body>
</soap:Envelope>
The namespace need not be same as hosted url of the service.The namespace can be any string.
e.g. Above service may be hosted at http://84.23.9.65/MyTestService , but still while invoking the Web Service from client the namespace should be the same which the serice class is having i.e.http://MyDomain.com/TestService

I agree with Sam in that the SOAP definition does not match what is expected. Here is just ONE solution it could be, I had to manually figure this error for myself:
My problem was that I changed the name of the web method but did not change the "MessageName" in the metadata tag.
[WebMethod(MessageName = "foo")]
public string bar()
{
}
It should be
[WebMethod(MessageName = "foo")]
public string foo()
{
}
hope that helps someone

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 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:operation elements you will see that it clearly states the soapAction for that operation:
<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.

I had same problem, it fixed after some checking:
<< Target WebService Exists but called method's not eXXXists. >>
my local service contain methods but target server(connecting server)
does not contain specified called method.
Check your program scenario again...

Just to help someone on this problem, after an afternoon of debug, the problem was that the web service was developed with framework 4.5 and the call from android must be done with SoapEnvelope.VER12 and not with SoapEnvelope.VER11

I had similar issue. To debug the problem, I've run Wireshark and capture request generated by my code. Then I used XML Spy trial to create a SOAP request (assuming you have WSDL) and compared those two.
This should give you a hint what goes wrong.

My error fixed by answer Mr. John Saunders : http://forums.asp.net/post/2906487.aspx
in short: difference between Namespace of ws
.asmx.cs with ws
.wsdl files.
1) [WebService(Namespace = "http://tempuri.org/")]
later web service namespace changed to :
2) [WebService(Namespace = "http://newvalue.com/")]
so we referenced (1) in application and web service is (2) now.
make them equal to fix your problem.

I had this same problem, but the solution for me was that I was pointing to the wrong web service. I had updated the web reference correctly. But we store the URl for the service in an encrypted file, and I didn't update the file with the correct service encrypted.
But all these suggestions really helped me to realize where to go for debugging.
Thanks!

I had the same problem after changing the namespace from "tempuri" in my Web Service.
You have to update your Service Reference in the project that is consuming the above service, so it can get the latest SOAP definitions.
Or at least that worked for me. :)

We had renamed some of our webservice project namespaces and forgot to update the website httphandlers config section with the namespace of the renamed projects.

I had the same error, i was able to resolve it by removing the 'Web Reference' and adding a 'Service Reference' instead

I got this error when I tried to call a method which did not exist. It only existed in a newer version of our webservice.

I had to sort out capitalisation of my service reference, delete the references and re add them to fix this. I am not sure if any of these steps are superstitious, but the problem went away.

I had a similar problem with the same error message:
System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction:
We utilize dynamic URL's in our web service calls. We have a central configuration server that manages the location of all web service calls so that our code can run in DEV, test or live without recompiling. The URL for a specific web service call for the test environment was incorrect in our configuration server. The web service call was being sent to the wrong server and the wrong web service.
So this error can simply be the result of the web service request not matching the web service being called.
It took running fiddler on the Web App server to see that the actual call was to the incorrect web service.

the problem is in the System.Web.Services.Protocols.SoapDocumentMethodAttribute
in the service. Please check it. it may changed.

I found out that my web reference was out of date and the code was calling a removed web service.

Related

Consume web service dynamically using HttpWebRequest without service reference

The application I work will have to send data to external system. The system system will have a web service (c# or java or php) and I need to consume it. Since there will be as many external system as clients, I need to get the WSDL file, method name and parameters as user input and send the data to the external system.
So, I am trying to invoke a web service dynamically using code available here
I tested few free web services available here
I find the SOAP location, method name and parameters from the the WSDL file and give the same as input.
The following service works as expected
http://soaptest.parasoft.com/calculator.wsdl
Location - http://ws1.parasoft.com/glue/calculator
Method Name - add
Parameter - x,y
But when I tried the same for the another free service by providing the SOAP location, and method name it throws 500 Internal server error.
http://www.predic8.com:8080/crm/CustomerService?wsdl
Location - http://www.predic8.com:8080/crm/CustomerService
Method Name - getAll
I confirmed these inputs are correct by testing the above wsdl in soapUI. The same location is used in soapUI request window.
I am not sure why it throws error. Please help me understand it.
Also please let me know if it is fine to get the service location from WSDL file and use the HttpWebRequest to get the response. I am afraid whether this method of invoking the web service will work irrespective the technology used to implement the web service.
EDIT:
The problem seems to with the SOAP envelope.
For http://soaptest.parasoft.com/calculator.wsdl even if we ignore xmlns:cal="http://www.parasoft.com/wsdl/calculator/, it gets executed successfully.
But for http://www.predic8.com:8080/crm/CustomerService?wsdl , if I ignore xmlns:ns="http://predic8.com/wsdl/crm/CRMService/1/, it throws internal server error.
Please share how I can be generic here
The problem appears to be with request data that you are using. The request is failing validation, so is the error.
If you import the provided wsdl, and validate create request, it is clear what the problem is.
There is an element id under Person and Customer and data must follow certain patter which is defined under the schema ../common/1
Here is the schema reference, which has simpleType restriction:
<xsd:simpleType name="IdentifierType">
<xsd:annotation>
<xsd:documentation>Identifier for business objects.</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[A-Z]{2}-\d{5}"/>
</xsd:restriction>
</xsd:simpleType>
So, id value should Something like AA-12345 i.e., two Capital letter, hyphen(-), and followed by 5 digits.
Change your request as per above pattern, and you should be good.
Hope this is helpful.

REST WCF Service Returns Method not allowed [duplicate]

In the process of developing my first WCF service and when I try to use it I get "Method not Allowed" with no other explanation.
I've got my interface set up with the ServiceContract and OperationContract:
[OperationContract]
void FileUpload(UploadedFile file);
Along with the actual method:
public void FileUpload(UploadedFile file) {};
To access the Service I enter http://localhost/project/myService.svc/FileUpload
but I get the "Method not Allowed" error
Am I missing something?
If you are using the [WebInvoke(Method="GET")] attribute on the service method, make sure that you spell the method name as "GET" and not "Get" or "get" since it is case sensitive! I had the same error and it took me an hour to figure that one out.
Your browser is sending an HTTP GET request: Make sure you have the WebGet attribute on the operation in the contract:
[ServiceContract]
public interface IUploadService
{
[WebGet()]
[OperationContract]
string TestGetMethod(); // This method takes no arguments, returns a string. Perfect for testing quickly with a browser.
[OperationContract]
void UploadFile(UploadedFile file); // This probably involves an HTTP POST request. Not so easy for a quick browser test.
}
The basic intrinsic types (e.g. byte, int, string, and arrays) will be serialized automatically by WCF. Custom classes, like your UploadedFile, won't be.
So, a silly question (but I have to ask it...): is UploadedFile marked as a [DataContract]? If not, you'll need to make sure that it is, and that each of the members in the class that you want to send are marked with [DataMember].
Unlike remoting, where marking a class with [XmlSerializable] allowed you to serialize the whole class without bothering to mark the members that you wanted serialized, WCF needs you to mark up each member. (I believe this is changing in .NET 3.5 SP1...)
A tremendous resource for WCF development is what we know in our shop as "the fish book": Programming WCF Services by Juval Lowy. Unlike some of the other WCF books around, which are a bit dry and academic, this one takes a practical approach to building WCF services and is actually useful. Thoroughly recommended.
I ran into this exact same issue today. I had installed IIS, but did not have the activate WCF Services Enabled under .net framework 4.6.
It sounds like you're using an incorrect address:
To access the Service I enter http://localhost/project/myService.svc/FileUpload
Assuming you mean this is the address you give your client code then I suspect it should actually be:
http://localhost/project/myService.svc
I've been having this same problem for over a day now - finally figured it out. Thanks to #Sameh for the hint.
Your service is probably working just fine. Testing POST messages using the address bar of a browser won't work. You need to use Fiddler to test a POST message.
Fiddler instructions...
http://www.ehow.com/how_8788176_do-post-using-fiddler.html
Only methods with WebGet can be accessed from browser IE ; you can access other http verbs by just typing address
You can either try Restful service startup kit of codeples or use fiddler to test your other http verbs
you need to add in web.config
<endpoint address="customBinding" binding="customBinding" bindingConfiguration="basicConfig" contract="WcfRest.IService1"/>
<bindings>
<customBinding>
<binding name="basicConfig">
<binaryMessageEncoding/>
<httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/>
</binding>
</customBinding>
My case: configuring the service on new server. ASP.NET 4.0 was not installed/registered properly; svc extension was not recognized.

C# Web Service client that will fail if WSDL is not available or invalid

My client hosts a few web services and has ASP.NET Web pages that will demo the web service and acts as a quick check to verify that the web service is up by the client. The problem is that the WSDL might be missing or invalid, but the Web Service will still work.
What I'd like to add to the ASP.NET web service client is a way to verify that the WSDL is there and valid, but have no idea where to start. Any suggestions would be greatly appreciated! Code behind is C#
I'm not entiery sure what you mean with verify that the WSDL is valid. Only thing I can suggest is, use an HttpWebRequest on the specific URI and see what response you get then either throw an exception based on specific status codes like 404 for example or handle it in a different way.
You can fetch the status code value
var request = (HttpWebRequest) WebRequest.Create("http://example.com/service.wsdl");
using (var r = (HttpWebResponse) request.GetResponse())
{
var result = r.StatusCode.ToString() == 200.ToString() ? "Success" : "Service not found";
Debug.WriteLine(result);
}
Hope this helps, goodluck.
Edit: if you know what services you're going to be testing you can simply add them as service reference in your client project and try to do an RPC on the service methods to see if it's available. Pictures below show to add a service reference.
Your scenario doesn't completely make sense. You could make a request to the service WSDL endpoint, http://something/service.asmx?wsdl and you could confirm that what comes back is a WSDL file. You could even validate it against the WSDL and XSD schemas.
This wouldn't tell you whether it was a WSDL that represented the service. It could conceivably be a WSDL for some totally different service.
Maybe more importantly, have you had problems where the service was available but the WSDL was not? In that case, rather than create diagnostics, I recommend that you fix the problem.

Semi-custom WCF proxy returns zeros, despite valid data coming back on wire

There is a series of SOAP services which I wish to call (across a series of services), and while the end points are well defined & documented, there is no WSDL data... so I decided to build my own.
In order to do so, I built a test WCF service which matches the known interface of the service I wish to call.
I then saved the WSDL it exposed, changed the base address the WSDL references, created my proxy (with wsdl.exe), added it to a test client project, and can successfully create a proxy and make calls which causes the SOAP service to send the expected response... only this expected response is not picked up by the proxy and returned to the calling code.
When looking at the back and forth traffic... I can clearly see that the service is replying with what I want.
Any suggestions as to how I might troubleshoot this and get the proxy to pickup the data?
Given the replies are effectively identical, I'm forced to look back at the differences between what my client is sending and another sends.
A known working app sends it's XML blob starting with the following:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
While my client immediately starts with the envelope (without the xml tag, and with one less namespace):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
The other difference is that the message within the body is prefixed by a namespace in theirs, while mine it is not... though both define this namespace within the tag.
Ala:
<s:Body>
<u:DoSomething xmlns:u="urn:http://some.namespace.org" />
</s:Body>
VS:
<s:Body>
<DoSomething xmlns="urn:http://some.namespace.org" />
</s:Body>
This is not a namespace:
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
It's setting the encoding style for the envelope which, even though it's not required per the SOAP spec, may be required by the specific implementation you're talking to. Do you have enough control over what you're sending from the client to get that put on there?
Other than that, the XML PI is not required and I think you're definitely on the right track looking at the body XML. This is almost always the case of some kind of namespace mismatch somewhere. Are you 100% positive the namespace URIs are identical?
The most likely problem is the VS version using a "default" XML namespace. There are soap parsers that I've worked which don't work correctly when using an un-aliased (default) namespaces. If you know using the u: alias works with the service, your proxy should also generate it even when every tag inside the s:Body element is prefixed with the alias.

Calling a web service: what am I doing wrong here?

I have the following code for consuming a service that is not working for me. Can anyone suggest what I can do to narrow down whats going wrong? I know this is vague so please tell me what you require to provide any suggestions.
The address is: http://localhost:57667/ExampleService.svc/
When visiting directly I get the 'You have created a service... message'
The code that goes wrong is here. It causes the following error:
_url = "http://localhost:57667/ExampleService.svc";
TextReader textReader = new StringReader(HttpPostClient.Post(new Uri(_url), bodyData.ToString(), _exampleServiceRequestEncoding, Properties.Settings.Default.HttpPostClientExampleAvailabilityTimeout));
ERROR MESSAGE:
When visiting this URL directly: http://localhost:57667/ExampleService.svc/ProcessRequest
The exception message is 'No component for key example.ExternalWebServiceStubs.Example.ExampleService was found'.
Castle.MicroKernel.DefaultKernel.get_Item(String key) at Castle.Facilities.WcfIntegration.WindsorInstanceProvider.GetInstance
many thanks,
The normal practice would be to create a proxy class via svcutil.exe (visual studio command prompt) or "add service reference" to consume the service, and then for you to use the methods of your proxy class to call your service's methods.
This tutorial should help (it's based on Visual Studio 2005, you didn't say what version you were using, but you should get a good grounding)
http://msdn.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic6
Since troubleshooting wcf services will be lot more easier when you provide web.config element also at service side.
My general guess here is, all the wcf services by default uses wsHttpBinding which will not allow direct calling of service like an asmx service we do.
You can replace wsHttpBinding with basicHttpBinding and disable the security to your service in order to get the service work like you are expecting.
Please add some more details about ExampleService.svc binding and it will help you get this resolved fast
Hope this will help

Categories