Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>
Posted
Updated 6-May-10 10:27am
v4

1 solution

So this is kind of embarassing. I was under the impression that if you add a Web Reference to a PC project that you would be forced to compile to the .Net 2.0 Framework...but I guess you don't. I was totally thrown by the fact that adding a web reference was so much more hidden in VS 2008 and the warning they supply that says "This will generate code based on .NET Framework 2.0 Web Services technology"...but I am able to add a Web Reference just like I did in VS 2005 and still compile to .Net 3.5. I really wish I would have tried that first instead of two days later. So...now it makes a lot of sense why I couldn't find any information on how to do this using a Service Reference instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900