The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

UPS Webservice in .NET

exmelloexmello Registered User regular
edited January 2011 in Help / Advice Forum
I would post this elsewhere, but it's scary out there and H/A is smart peoples.

I'm going through the approval process on a 3rd party web service API (UPS) and they need me to send them the XML from various requests and responses. The problem is since I implemented my solution using C#, I don't have easy access to the XML sent and received. There's some .NET voodoo going on when you add a web reference and they hide any way to access the plain text XML.

I've looked everywhere online for a way and the top 3 suggestions I see are:
  1. Edit the web.config to trace your socket connections
  2. Write a SoapExtension to process the content before/after serialization.
  3. Use a proxy to intercept the message.

I've tried (1), and since the XML data was so large, there were gaps in the data and I couldn't create a valid XML file by what I could parse out of the log file.

I tried (2), but can't get any of the msdn examples to work. I think this is because the SoapExtensionAttributes only work on your own WebMethods, not invocations of outside services.

I saw instructions on (3) somewhere, but I forgot to bookmark it and can't find it again.

Unfortunately, UPS is fairly stingy on developer support, so I think I'm out of luck there.

Help me H/A, I've been stuck on this for almost a week.

exmello on

Posts

  • wmelonwmelon Registered User regular
    edited December 2010
    Might I suggest you check out Fiddler. It'll capture any HTTP/s traffic you do and you should be able to easily scrape the data out of it.

    wmelon on
  • exmelloexmello Registered User regular
    edited December 2010
    I'm going to give Fiddler a try. Has anyone here used it to listen to a local .NET client consuming an outside web service? Do I have to listen on a specific port or something?

    exmello on
  • wmelonwmelon Registered User regular
    edited December 2010
    It would be whatever port you're consuming the web service on. Generally that'll be http (80) or https (443). Both of which are covered by default by fiddler.

    wmelon on
  • exmelloexmello Registered User regular
    edited December 2010
    I'm not having much luck reading the HTTPS call, even after following their instructions to install trusted certificates. It either hangs or doesn't show up at all.

    exmello on
  • wmelonwmelon Registered User regular
    edited December 2010
    I would suggest trying to get it to work in firefox. I've never successfully been able to get IE to consistently ignore certificate errors.

    wmelon on
  • exmelloexmello Registered User regular
    edited December 2010
    I am using firefox already. I just can't quite figure out how to get fiddler to see .NET services. The page I'm running calls IIS and IIS is making the HTTPS call. I'm trying some instructions to have my application use 127.0.0.1:8888 as a proxy, but I'm failing spectacularly. This isn't really my area of expertise.

    exmello on
  • ChickeenChickeen Registered User regular
    edited December 2010
    So you've tried serializing the requests and responses to file and can't get it to work? That seems like the easiest thing to do.

    Chickeen on
  • exmelloexmello Registered User regular
    edited December 2010
    Unfortunately .NET abstracts the serialization away. Unless theres something you know that I'm missing?

    exmello on
  • ChickeenChickeen Registered User regular
    edited December 2010
    Maybe we're talking about two different things?

    I add a web service reference to a .NET app, and classes and what not are generated for the reference. When calling a method of the web service, I load up an class object that the method accepts as an argument, make the web service call, and the method returns an object for the response.

    I'm talking about serializing the objects passed and returned into .xml files.

    Chickeen on
  • wmelonwmelon Registered User regular
    edited December 2010
    exmello wrote: »
    I am using firefox already. I just can't quite figure out how to get fiddler to see .NET services. The page I'm running calls IIS and IIS is making the HTTPS call. I'm trying some instructions to have my application use 127.0.0.1:8888 as a proxy, but I'm failing spectacularly. This isn't really my area of expertise.

    Oh. You'll need to be running fiddler on the server. I assumed you were testing locally.

    wmelon on
  • virgilsammsvirgilsamms Registered User regular
    edited December 2010
    Check out WireShark (formerly Ethereal), which is a packet capture and analysis tool. Sounds like Fiddler is something similar. It will capture all inbound and outbound traffic to any port.

    virgilsamms on
  • wmelonwmelon Registered User regular
    edited December 2010
    Check out WireShark (formerly Ethereal), which is a packet capture and analysis tool. Sounds like Fiddler is something similar. It will capture all inbound and outbound traffic to any port.

    Wireshark won't be able to read the encrypted HTTPS packets. Fiddler acts as a proxy and can therefore decrypt the packets as it already has the keys going back and forth.

    wmelon on
  • virgilsammsvirgilsamms Registered User regular
    edited December 2010
    Ah yes, good point.

    virgilsamms on
  • GanluanGanluan Registered User regular
    edited December 2010
    Maybe I'm confused but it's very easy to access the XML sent and received from a web service in .NET. You've got a client app running and you're trying to provide the XML input/output from an outside service, correct?

    To do it within the code, you can change the proxy class (i.e., the Reference.cs under your Service Reference) generated by VS so that it returns XML instead of the auto-generated type. Of course, that will be overwritten anytime you update the reference. There are also very easy ways in .NET to serialize objects into XML, so you could serialize the enter request/response object.

    If you don't need it programatically and just want to view it, Fiddler is the way to go, as mentioned. wmelon is right, you need to run Fiddler on the server that is actually making the service call.

    Ganluan on
  • exmelloexmello Registered User regular
    edited December 2010
    I've been sick so I haven't been able to get back to this lately.
    wmelon wrote: »
    exmello wrote: »
    I am using firefox already. I just can't quite figure out how to get fiddler to see .NET services. The page I'm running calls IIS and IIS is making the HTTPS call. I'm trying some instructions to have my application use 127.0.0.1:8888 as a proxy, but I'm failing spectacularly. This isn't really my area of expertise.

    Oh. You'll need to be running fiddler on the server. I assumed you were testing locally.

    I am running it locally right now, just fiddler wasn't picking it anyway and I read this was because the serverside code (still on my machine while I'm developing) is running under this IIS user.
    Ganluan wrote:
    Maybe I'm confused but it's very easy to access the XML sent and received from a web service in .NET. You've got a client app running and you're trying to provide the XML input/output from an outside service, correct?

    To do it within the code, you can change the proxy class (i.e., the Reference.cs under your Service Reference) generated by VS so that it returns XML instead of the auto-generated type. Of course, that will be overwritten anytime you update the reference. There are also very easy ways in .NET to serialize objects into XML, so you could serialize the enter request/response object.

    If you don't need it programatically and just want to view it, Fiddler is the way to go, as mentioned. wmelon is right, you need to run Fiddler on the server that is actually making the service call.

    This was kind of one of one of the first things I tried, but when it didn't work I started searching online, and everyone seemed to pointing in the direction of SOAP extensions and tools like fiddler.

    I think part of the problem is that UPS request isn't really valid XML, like it sends 2 separate documents in one call or something.

    exmello on
  • GanluanGanluan Registered User regular
    edited December 2010
    exmello wrote: »
    I think part of the problem is that UPS request isn't really valid XML, like it sends 2 separate documents in one call or something.

    Well, it is likely valid XML, otherwise the .NET serialization would shit its pants.

    Did you try changing your return values in the generated proxy class? If you find the method name you're calling, you should be able to just change "public MyObject GetStuff()" to "public XmlElement GetStuff()" and then throw it to a string. I may have the class name wrong on the XML but the idea is the same.

    Ganluan on
  • exmelloexmello Registered User regular
    edited January 2011
    No luck with any of the suggestions.

    I was sick for a week straight then was on vacation for a while. I was frustrated with this so much that I tried just working on some other stuff for a while, but management pulled me back to this.

    Does anyone specifically have any experience developing a .NET application using the UPS Shipping API? They offer little to no developer support, and I have more questions than just my problem above

    exmello on
  • cravipatcravipat CFKPW? Registered User regular
    edited January 2011
    exmello wrote: »
    I'm going to give Fiddler a try. Has anyone here used it to listen to a local .NET client consuming an outside web service? Do I have to listen on a specific port or something?

    This is a little late but you need to setup .NET to send it's requests through the Fiddler proxy in order for the external web service calls to show up. You can do it two ways. Update the web.config to contain
    <system.net>
      <defaultProxy>
        <proxy  proxyaddress="http://127.0.0.1:8888" />      
      </defaultProxy>
    </system.net>
    

    Or add this to Application_Start in Global.asax
    WebRequest.DefaultWebProxy = new WebProxy("http://127.0.0.1:8888");
    

    Also don't forget to remove those once you're done testing. Otherwise your site will break once you close Fiddler and you stare at it for an hour wondering why the site doesn't load. Not that I've ever done anything like that.

    cravipat on
    nw1m8qQ.pngwNA4DEe.png6W3X2nk.png
    Super Mario Maker ID: DBB-1RH-JJG
  • exmelloexmello Registered User regular
    edited January 2011
    I had already tried
    System.Net.GlobalProxySelection.Select = new System.Net.WebProxy("127.0.0.1", 8888);
    

    in the Global.asax Application_Start earlier and had no luck. I'll try your way if I get a chance, but it seems equivalent.

    exmello on
Sign In or Register to comment.