Good day.
i am hoping that someone could assist me. I am creating a web service (this is the first time i have ever created a web service). i have worked with web services/API in the past from a client side by creating soap xml messages and sent and received messages back and forth. Now i need to create my own web Service and am needing a little assistance with creating it correctly.
i initially created a simple web method as follows.
[WebMethod(Description = "Soap Request")]
public string Request(string xmlDocument)
{
//do work
}
but when i tried consuming this method i received the following error:
System.Web.HttpRequestValidationException: A potentially dangerous
Request.Form value was detected from the client
i then tried (after googling) to change the method as follows:
[WebMethod(Description = "Soap Request")]
public string Request(XmlDocument xmlDocument)
{
//do work
}
but that didnt seem to work either, when i tried to send an xml soap message to this method it came through empty. What i then did was to create the method with parameters matching the elements in my xml Soap message. the method then picked up each element and populated the parameters correctly as follows.
public void Request(string parm1, string parm2)
{
//do work
}
with the following xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Request>
<tem:Parm1>111</tem:Parm1>
<tem:Parm2>222</tem:Parm2>
</tem:Request>
</soapenv:Body>
</soapenv:Envelope>
i would like to find out, is this the correct way to handle the incoming message or is there something else i should be doing to accept the incoming xml message? i thought that i could create the method as i had initially done that it would accept the xml string passed to it and i could work with the message as i did when receiving xml message back from web services i used in the past.
please forgive me if i have duplicated a question, i could not find anything that would give me a definite answer.
i have started creating the web service in Visual Studio 2019.
any assistance or advise would be greatly appreciated.
I was having the exact same issue. So in my project I just added this to my web.config/system.web/httpRuntime:
requestValidationMode="2.0"
And It just worked!
Well that's a mouthful for a title. Let me start out by saying that I am not a programming per se but a DBA. I can write some MSSQL query with the best of them but my knowledge of C# is pretty limited. I have a piece of software that I need to communicate with via web services to push some data to all within the constraints of SQL Server Integration Services. I can read from the DB directly but I can not write to it. I'm querying some data, emailing that data, and I need to write back to the software for reach record we emailed through web services. The WSDL is available but like I said, zero knowledge of C#. I was able to build a SOAP envelope through SOAPUI that works perfectly and I would like to figure out a way call SOAP using a C# script in my SSIS package.
I have also tried to run this in the Web Service Task in SSIS and my WSDL file only gives me 4 methods when I should have close to a hundred. It would be easier there to sort out but I understand there are some limitations with the SSIS Web Service Task.
I have seen this thread: Client to send SOAP request and received response
Which unfortunately does not work for me when I copy and paste my SOAP and header into the code. To throw another wrench this thing, this is a protected web services which requires 3 credentials to have a token issued for passing data back and forth. A side question is can I run multiple SOAP calls (first to authenticate, then to push my data into the web service) through a C# script?
Here was my second soap call after getting the token that I was able to run:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:v2="http://www.WSAPI.AMS360.com/v2.0">
<soapenv:Header>
<v2:WSAPIAuthToken>
<v2:Token>tokenremoved</v2:Token>
</v2:WSAPIAuthToken>
</soapenv:Header>
<soapenv:Body>
<v2:InsertActivity_Request>
<!--Optional:-->
<v2:Activity>
<v2:AssignedTo>93725c05-f77b-49a1-9edd-6ce9fd5505c1</v2:AssignedTo>
<!--Optional:-->
<v2:ActivityType>customer</v2:ActivityType>
<v2:ActivityAction>% of ownership</v2:ActivityAction>
<!--Optional:-->
<v2:ActivityDate>11/04/2014</v2:ActivityDate>
<!--Optional:-->
<v2:ActivityTime>11:54</v2:ActivityTime>
<!--Optional:-->
<v2:EmployeeCode>!$5</v2:EmployeeCode>
<v2:Description>web services test code successfully inserted</v2:Description>
</v2:Activity>
</v2:InsertActivity_Request>
</soapenv:Body>
</soapenv:Envelope>
We have an old bit of code, ASMX WebService, that we have lost the source to. I am trying to replicate the behavior of this so we can take control of it once again without affecting any of the clients.
I have created a class that mimics the behavior and properties of the response, and a soap request returns as follows
<soap:Body>
<LoginResponse>
<LoginResult>
<UserId>string</UserId>
<Password>string</Password>
</LoginResult>
</LoginResponse>
Now the service I am trying to replicate returns
<soap:Body>
<LoginRS xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserId>string</UserId>
<Password>Password</Password>
</LoginRS>
</soap:Body>
Now LoginRS is the name of the class I have made. My question is how do I make my response look like the second response.
I am replicating this in c# ASMX and am using the following
[WebMethod(MessageName="Login")]
public LoginRS Login(string password, string userId)
Thanks for you time.
If your objective is to reverse engineer the service, and if the service dll is with you, you can use .NET Reflector (google it) to read the dll and provide you the exact source code.
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.
[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.