Rick Kierner posted on September 29, 2008 17:26

I recently answered a question to a colleague that deserves its own blog posting.  The question simply stated is:

I have two webservices that share types:

webSvc1 at http://myServer/WS/webSvc1.asmx
webSvc2 at http://myServer/WS/webSvc2.asmx

When I generate the proxy for these two services I use:

wsdl /sharetypes http://myServer/WS/webSvc1.asmx http://myServer/WS/webSvc2.asmx /appsettingurlkey: MyOrgNamespace.MyAppName URL /n:MyOrgNS.Proxy /o:"C:\MyWebApp\App_Code\MyProxy.cs" /l:CS

The problem is that the appsettingurlkey is the same for each service
in the proxy file. I want to be able to specify multiple
appsettingurlkey parameters. How is this accomplished. I figure
since the /sharetypes parameter became available, there should be a
solution for specifying the appsettingurlkey specifically for each
service identified

As it turns out, I asked this question on a forum over a year ago and never got a response. I eventually figured it out but got lazy and didn't respond to my own post with the answer.  Here's the answer:

The command line wsdl command doesn't allow for this explicitly.  However, you can use a properties file to make this work. 

Here is the XML Parameter file

 

0:  <wsdlParameters xmlns="http://microsoft.com/webReference/">
1:   <nologo>true</nologo>
2:   <parsableerrors>true</parsableerrors>
3:   <sharetypes>true</sharetypes>
4:   <language>CS</language>
5:   <namespace>MyOrgNS.Proxy</namespace>
6:   <documents>
7:   <document>http://myServer/WS/webSvc1.asmx?WSDL</document>
8:   <document>http://myServer/WS/webSvc2.asmx?WSDL</document>
9:   </documents>
10:   <appSettingUrlKey>MyOrgNamespace.MyAppName</appSettingUrlKey>
11:   <appSettingBaseUrl>http://myServer/WS/</appSettingBaseUrl>
12:   <out>C:\MyPath\Proxy.cs</out>
13:  </wsdlParameters>
</PRE< P>

 

Here is the WSDL Command:

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\WSDL" /Parameters:{ENTER_PATH_TO_ABOVE_XML_FILE}"

The important part to note is that each web service starts off with http://myServer/WS/... in the properties XML file.  Then the appSettingBaseURL is "http://myServer/WS/".  Finally, note that the app Setting URL Key is specified as MyOrgNamespace.MyAppName.  In your client's app or web.config file, you'll need to add <add key="MyOrgNS.Proxy" value="http://devServer/SomeURL/"/>  The .cs file that is generated from running the WSDL tool will replace "http://myServer/WS/" with "http://devServer/SomeURL/" before making the http request to the actual service.

Technorati Tags: ,,

Posted in:   Tags:
Rick Kierner posted on July 17, 2008 11:50

If you're dealing with an ASP.NET web service and a web front end that is using ajax, it may be too much trouble to attempt to parse the XML.  XML can be clunky and contain way more information that you need.  It's pretty simple to change the output of a web service method to return JSON:

   1:  [WebService(Namespace = "http://tempuri.org/")]
   2:  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   3:  public class Service : System.Web.Services.WebService
   4:  {
   5:      public Service () {}
   6:   
   7:      [WebMethod]
   8:      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
   9:      public MyObject HelloWorld(){return new MyObject();}
  10:  }
  11:   
  12:  public class MyObject
  13:  {
  14:      public MyObject()
  15:      {
  16:          MyString = "Test";
  17:          MyInt = 10;
  18:      }
  19:   
  20:      public string MyString;
  21:      public int MyInt;
  22:  }

Note Line 8.

But Rick,  JSON is harder to parse with my .Net class library than xml is.  Well, I don't know that I would necessarily recommend this approach for a .Net to .Net type of communication.  But let's just imagine that you want to do real ajax.  I'm not talking the ASP.NET ajax.  Now let's leverage a JavaScript library like JQuery.  JQuery can parse that JSON format right into a JavaScript object.  Just awesome.  I may post some more on this in the future.  I just thought the ResponseFormat property was kickin.

Technorati Tags: ,,,

Posted in:   Tags: , , ,
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2013 Rick.Brain.Flush()