|
Try running in the debugger and navigating to http://localhost/Service1.asmx (or right-click the asmx file and choose view in browser).
You should see your methods listed - click one to see sample requests/responses for the method.
(if you run in debugger you can set breakpoints in your methods so you don't have to use log entries...)
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Under the PostMethod method, I can see this section under the HTTP Post
POST /xmlservice1dot1/service1.asmx/PostMethod HTTP/1.1
Host: ***.***.**.**
Content-Type: application/x-www-form-urlencoded
Content-Length: length
test=string
However, its not yet clear to me on how to consume the PostMethod. I was thinking you could consume it by creating an HTTP post to http://localhost/Service1.asmx/PostMethod?test=string but I am not sure if it can be done. I was doing a post to http://localhost/Service1.asmx/HelloWorld and it works fine but I cant get it to work for PostMethod. Can you please suggest a way for me to do it? Thanks in advance.
|
|
|
|
|
samir.abda wrote: I was doing a post to http://localhost/Service1.asmx/HelloWorld and it works fine but I cant get it to work for PostMethod.
From the browser address bar you'll need to be able to call using GET.
Add this to your web.config in the system.web section:
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
</webServices>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That seemed to do the trick. Thank you.
Another question, given that http://localhost/Service1.asmx/PostMethod?test=string already works, is there a way to make the value of test dynamic? Like putting it in an XML for example? I tried posting something like the XML below to the web method but it does not work. Hope you can help me with a solution.
<test>This is a test string</test>
|
|
|
|
|
What do you mean by "make the value of test dynamic"?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
For example, if I post to this URL, http://localhost/Service1.asmx/PostMethod?test=string, the value of the parameter test would be string . Is there a way to do this dynamically, like call http://localhost/Service1.asmx/PostMethod and just post the XML containing the value for the test parameter?
|
|
|
|
|
Are you doing this from code? I have no idea how you're consuming your web service
If you're calling your web service from another application, Visual Studio can create a servicereference for you which will give you a nice proxy class you can use to call the web service methods just like they're local...
Mark Salsbery
Microsoft MVP - Visual C++
modified on Thursday, May 26, 2011 4:40 AM
|
|
|
|
|
Oh sorry for that. This is how I consume the web service. Basically, I post an XML to the web method
XmlDocument _xml = new XmlDocument();
_xml.Load(filePath);
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertificatePolicy;
WebRequest _request = WebRequest.Create((WebServiceURL));
_request.Credentials = new NetworkCredential(UserName, Password);
_request.Method = "POST";
_request.ContentType = "text/xml";
XmlTextWriter xw = new XmlTextWriter(_request.GetRequestStream(), Encoding.UTF8);
_xml.WriteTo(xw);
xw.Close();
WebResponse response = _request.GetResponse();
response.Close();
|
|
|
|
|
Why not use Visual Studio to make a proxy class for you so you don't have to do that all yourself?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Sorry I haven't mentioned that the real web service is created in Java. What I provided was just a test webservice to verify my solution. I have no control on the Web Service since it is owned by the client. I am not sure if creating a proxy class is still applicable even if the Web Service is not creating in .Net. Will it work even in this case? Sprry, I know I could verify this on my own but right now, there are no Java test web services so I have created my own, in .Net. I really appreciate your help on this. Thank you in advance.
|
|
|
|
|
I don't know about Java....you could ask on the Java board though!
Without .NET I don't believe the proxy class would apply...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Basically, as Mark suggested, you need to navigate to your webservice through your browser. From there, you can see the format of the XML messages that you will send/receive. You will also see the headers that you need to assign to your _request object before firing it up. I can see in your code that you havent assigned the SOAPAction header in your request object. You also need to set that if you are going to use SOAP, like this.
_request.Headers["SOAPAction"] = "[Value of SOAPAction, you can see this by navigating on the web method of the web service, through browser]";
After setting this, I believe your'e good to go. Just make sure that you are using the right format of XML that was provided on the web service.
Ignorance of the ability brings disability.
|
|
|
|
|
Hello,
I am using SOAP method to get a list of tours from a web service in the internet. The pictures in the tourlist do not show up because of LOCALHOST definition in their source. How can I set LOCALHOST in web config to use web services root address.
Thank you!
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
You can't. There is no setting in the web.config file that will convert the address in the data you receive. Do you know any developers who can help you with this?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I was expecting a solution rather than a judgment.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Once you get the data back, why not just do a string replace LOCALHOST -> real host name? The issue isn't on your side, the web service isn't implemented properly. A web service should *NEVER* be returning LOCALHOST in URLs. You just need to work around the web service bug with the string replace.
|
|
|
|
|
Thank you very much that is what I needed.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
I guess you did find a developer to help you.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You are not a developer but he was because of his answer (it doesn't matter if he is a beginner or advanced one). His solution worked out and will also work when upload my web service on any server. A developer mean is not God of coding? Are you?
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
JUNEYT wrote: You are not a developer but he was because of his answer
Thanks I needed a good laugh at the end of the day
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I am glad that I made you happy somehow but please have a toothpaste and toothbrush. Take it easy.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
A toothbrush and toothpaste? Sorry I think something got lost in translation. Why not just give up while your behind.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
We were actually not translating something but your behavior...
I didn't ask you if he was a developer. I was looking for a solution and he provided me so.
So don't give up! keep coding your own behavior.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
JUNEYT wrote: I was looking for a solution and he provided me so.
Yes, you asked "How can I set LOCALHOST in web config..."
To which my replay was, "You can't. There is no setting in the web.config file..."
How is that not a solution? Must have gotten lost in the translation, or perhaps I didn't use enough toothpaste
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark, I'm surprised by this response. The last bit is unusually unkind of you; you're always very helpful, in my experience. Are you having a bad day? Yes, the question implied a solution approach that won't work, but we are not all professionals here, with years of experience to draw from, and sometimes we get lost on a wrong track because of it. Your answer was initially excellent, but it wouldn't have taken a lot of effort for an expert like you to suggest another approach. I hope you have a better day tomorrow, and thank you for the help you've given me, a perpetual tyro, over the years...
Will Rogers never met me.
|
|
|
|