I have a PC Windows Forms project and a Web Service that I'd written in VS 2005 and am trying to upgrade to use VS 2008. I've created the Web Service just fine, and now am trying to create the PC project. The code in the PC that calls the Web Service does not work the same because Visual Studio 2008 uses Service References instead of Web Service references. So in the old version of my PC program, I added a web references that pointed to my local host version of the web service. Then in code, I would change what URL the web reference should hit based on what selection the user made on a form. This way I had one web reference in my project but it could hit a developers local computer or our Development servers or our Production servers. I can't figure out a way to accomplish this in VS2008. Is there a way to change in code what URL the service is going to hit? Or isn't this possible to do in VS 2008 using the service references and instead I would have to create a service reference for each individual URL that I may want to hit?
-----------
I found a way to dynamically change the address like this:
Dim obj as New MyService.MyServiceSoapClient
obj.Endpoint.Address = New System.ServiceModel.EndpointAddress("http://DifferentServerName/MyProjectName/MyWebService.asmx")
But it doesn't work between http and https sites...
I get the following error:
The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via
I can get things to work the way I want by changing the app.config file in my PC program. I but I want to do this in code. Does anyone know how? Here is what I have in my app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyWebServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport"> <!-- If I leave this set to None it works for http sites, if I change to transport it works for https -->
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/MyProject/MyWebService.asmx"
binding="basicHttpBinding" bindingConfiguration="MyWebServiceSoap"
contract="MyWebService.MyWebServiceSoap" name="MyWebServiceSoap" />
</client>
</system.serviceModel>