Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Weird Web Services App

I am working on a client application that is kind of strange, and I’m not sure how to pull this off. The client uses a web service that was developed by another party that I don’t have access to. There are already a number of clients that use this web service on their website. It’s a simple XML post to the service, with a response. What we are trying to accomplish is the XML to be posted to a service that I would create, do some processing on that XML string, then post the same XML string to the service that is already in use, pass its response back to my service, my service would then pass the response back to the client. The reason it has to be done this way is because we only want the clients to only have to change the URL they are posting to, and we cannot make any changes to the original web service.

I have implemented web services before, but I’ve never built one. So I’m not sure how to do this. I created simple “Hello Word” web service from a tutorial that works OK, but as soon as I post the XML string to it craps out. Any light you can shed would be great. I am doing this in ASP/VB.net in Visual Studio.
0
ed124
Asked:
ed124
  • 6
  • 4
1 Solution
 
Bob LearnedCommented:
1) 2.0 or 1.1?

2) It sounds like you need to create a "wrapper" web service, that has an instance of another web service.

3) Web service proxies are a possibility.

Bob

0
 
ed124Author Commented:
1.1

Can you point me to some tutorials or samples of a wrapper web service?
0
 
sdeenCommented:

What do you mean "it craps out"? Can you post any error info?

Does the same thing happen if you post simple text, instead of XML?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ed124Author Commented:
It errors out no matter what I post

I get: The remote server returned an error: (500) Internal Server Error.

*****Here is my test request:*****

Dim xmlRequest As String = "xmlRequest=<Request>Test</Request>"

Dim objRequest As HttpWebRequest = CType(WebRequest.Create("http://localhost/WebService1/Service1.asmx/Test/"), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = xmlRequest.Length
objRequest.ContentType = "application/x-www-form-urlencoded"

myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(xmlRequest)
myWriter.Close()

Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse) <<< *****Errors out here*****
Dim sr As New StreamReader(objResponse.GetResponseStream())
Response.Write(sr.ReadToEnd())

*****Here is my Test service:*****

<WebMethod()> _
    Public Function Test(ByVal xml) As String
        Return xml
    End Function


0
 
sdeenCommented:
You seem to be calling this service as a regular web request, instead of the proper way for invoking a service.

Assuming the service you're trying to access is working properly, the right way to call it is by adding a Web Reference to it in your project, and then you can instantiate it as you would any object.

Let's say the service you're trying to access has a class called XMLClass and a method called GetXMLResponse, and you named the web reference XMLWebService. Your code would then look something like this:

<WebMethod()> _
    Public Function Test(ByVal xml) As String  
        Dim XMLClass1 As  New XMLWebService.XMLClass
        String SomeText = XMLClass1.GetXMLResponse(xml)
        Return xml
    End Function


This is realy all you should need. Hope this helps.

0
 
ed124Author Commented:
The reason the request is like that is because many clients already are using the webservice, and most are requesting from classic asp. And like I said, all I want the clients to have to change is the URL they are posting to.

With the test code, all I was trying to do was pass an XML string, and have it respond with same XML. I also just had it to return “Hello World” and it did not work.
0
 
sdeenCommented:
I see. I thought your code was to call the other (the original) web service.

I'd suggest using a tool such as WFetch to see what the exact error is from the web server. You can find it in the free IIS Resources pack from Microsoft.

Does it work when you test the asmx file in a web browser?
0
 
ed124Author Commented:
It works fine just invoking through the browser.

I just tried Wfetch, and I did get this error: 0x2745 (An established connection was aborted by the software in you host machine.): Socket Error on Recieve
0
 
sdeenCommented:
Beats me then. I just tried your code (except in c#), and tested with WFetch and it works fine. As far as I can tell, the only problem in your code is you're passing a parameter called 'xmlRequest', and your method expects 'xml'. But I'm assuming that's just in your sample here.

Good luck. If you figure it out, post the solution.
0
 
ed124Author Commented:
Thanks anyway. Anyone else?
0
 
ed124Author Commented:
I went another direction on this, but the suggestion to use WFetch was a big help. So I'm giving sdeen the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now