<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>My Fried Tech! - Web Services</title>
    <link>http://www.myfriedmind.com/techBlog/</link>
    <description>oddities from my work</description>
    <language>en-us</language>
    <copyright>Matt Mcknight</copyright>
    <lastBuildDate>Thu, 19 Nov 2009 22:29:18 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>matt@em.org</managingEditor>
    <webMaster>matt@em.org</webMaster>
    <item>
      <trackback:ping>http://www.myfriedmind.com/techBlog/Trackback.aspx?guid=b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea</trackback:ping>
      <pingback:server>http://www.myfriedmind.com/techBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.myfriedmind.com/techBlog/PermaLink,guid,b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea.aspx</pingback:target>
      <dc:creator>papabear</dc:creator>
      <wfw:comment>http://www.myfriedmind.com/techBlog/CommentView,guid,b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea.aspx</wfw:comment>
      <wfw:commentRss>http://www.myfriedmind.com/techBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was setting up a Man in the Middle webservice to intercept a message coming in so
that I could do some processing of it on the side. Don't worry, it was our webservice.
My process is fairly simple:
</p>
        <ol>
          <li>
accept the submitted object 
</li>
          <li>
forward the object to the old web service 
</li>
          <li>
do what I wanted with the info</li>
        </ol>
        <p>
Step #2 appears fairly straightforward, and for the most part it is. 
</p>
        <ol>
          <li>
Create a (new) Web Service. 
</li>
          <li>
Expose the same public WebMethods. 
</li>
          <li>
Add a 'Web Reference' to the (old) Web Service 
</li>
          <li>
Create a new Web Service object of the old Web Service 
</li>
          <li>
Pass the received object onward</li>
        </ol>
        <p>
The problem that occurs is that because the (new) Web Service has to be all-inclusive
it creates its own object type. While this is acceptable in .Net (since it goes by
.net classnames) this gets all out of whack in the XML. This is because the XML uses
a different namespace process - and since the (new) Web Service uses the same object
as the (old) Web Service, albeit with a different .net namespace one of the things
that it includes as an Attribute is the XML namespace. So
</p>
        <ul>
          <li>
The two classes have different .net namespaces 
</li>
          <li>
The two classes have the exact same XML namespace</li>
        </ul>
        <p>
The compiler does not catch this because it is only looking at the .net namespace.
So it will give you all sorts of helpful suggestions. 
</p>
        <p>
However....
</p>
        <p>
There is a simpler way to do it. Basically, since you KNOW that the incoming and outgoing
objects are the same, you are simply going to override the class that the Web Reference
uses to tell it to use the original class.
</p>
        <p>
If you initially open up the Web Reference to your (old) Web Service you are not going
to see the file you need. You need to go up to the File Menu and select Project, Show
All Files. 
</p>
        <p>
          <img src="http://www.myfriedmind.com/techBlog/content/binary/MiMXMLShowAll.gif" border="1" />
        </p>
        <p>
Now you will see the file that you want over in the Solution Exploerer -&gt; Reference.cs. 
</p>
        <p>
          <img src="http://www.myfriedmind.com/techBlog/content/binary/MiMXMLReference.gif" border="1" />
        </p>
        <p>
Open that puppy up and make the necessary changes, just remember to wipe out the (new)
objects that will be in there. All you want to leave are the methods, and those should
now be passing the classes from the (old) Web Service.
</p>
        <p>
Happy coding!
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.myfriedmind.com/techBlog/aggbug.ashx?id=b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea" />
      </body>
      <title>Man in the Middle Web Services and XML Serialization errors</title>
      <guid isPermaLink="false">http://www.myfriedmind.com/techBlog/PermaLink,guid,b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea.aspx</guid>
      <link>http://www.myfriedmind.com/techBlog/2009/11/19/ManInTheMiddleWebServicesAndXMLSerializationErrors.aspx</link>
      <pubDate>Thu, 19 Nov 2009 22:29:18 GMT</pubDate>
      <description>&lt;p&gt;
I was setting up a Man in the Middle webservice to intercept a message coming in so
that I could do some processing of it on the side. Don't worry, it was our webservice.
My process is fairly simple:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
accept the submitted object 
&lt;li&gt;
forward the object to the old web service 
&lt;li&gt;
do what I wanted with the info&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Step #2&amp;nbsp;appears fairly straightforward, and for the most part it is. 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Create a (new) Web Service. 
&lt;li&gt;
Expose the same public WebMethods. 
&lt;li&gt;
Add a 'Web Reference' to the&amp;nbsp;(old) Web Service 
&lt;li&gt;
Create a new Web Service object of the old Web Service 
&lt;li&gt;
Pass the received object onward&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The problem that occurs is that because the (new) Web Service has to be all-inclusive
it creates its own object type. While this is acceptable in .Net (since it goes by
.net classnames) this gets all out of whack in the XML. This is because the XML uses
a different namespace process - and since the (new) Web Service uses the same object
as the (old) Web Service, albeit with a different .net namespace one of the things
that it includes as an Attribute is the XML namespace. So
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The two classes have different .net namespaces 
&lt;li&gt;
The two classes have the exact same XML namespace&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The compiler does not catch this because it is only looking at the .net namespace.
So it will give you all sorts of helpful suggestions. 
&lt;/p&gt;
&lt;p&gt;
However....
&lt;/p&gt;
&lt;p&gt;
There is a simpler way to do it. Basically, since you KNOW that the incoming and outgoing
objects are the same, you are simply going to override the class that the Web Reference
uses to tell it to use the original class.
&lt;/p&gt;
&lt;p&gt;
If you initially open up the Web Reference to your (old) Web Service you are not going
to see the file you need. You need to go up to the File Menu and select Project, Show
All Files. 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.myfriedmind.com/techBlog/content/binary/MiMXMLShowAll.gif" border=1&gt;
&lt;/p&gt;
&lt;p&gt;
Now you will see the file that you want over in the Solution Exploerer -&amp;gt; Reference.cs. 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.myfriedmind.com/techBlog/content/binary/MiMXMLReference.gif" border=1&gt;
&lt;/p&gt;
&lt;p&gt;
Open that puppy up and make the necessary changes, just remember to wipe out the (new)
objects that will be in there. All you want to leave are the methods, and those should
now be passing the classes from the (old) Web Service.
&lt;/p&gt;
&lt;p&gt;
Happy coding!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.myfriedmind.com/techBlog/aggbug.ashx?id=b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea" /&gt;</description>
      <comments>http://www.myfriedmind.com/techBlog/CommentView,guid,b41b4f63-6aaa-49cb-b1b8-de5b2dabfcea.aspx</comments>
      <category>Asp.Net</category>
      <category>c#</category>
      <category>Coding Tricks</category>
      <category>VB.Net</category>
      <category>Web Services</category>
    </item>
  </channel>
</rss>