none
Simple WCF service MSDN example RRS feed

  • Question

  • Hi all,

    I am completely new to WCF so before I start developing WCF which I will use in my application I wanted to try few samples to see what it is all about.

    Well although trying few examples (see below) I can't make it work.

    1. http://msdn.microsoft.com/en-us/library/dd938879.aspx

    2. http://msdn.microsoft.com/en-us/library/cc488004%28v=vs.90%29.aspx

    1 and 2 are type of wcf service I will need in the end.

    I decided above two are a little to complicated for a newbie. So I went and tried the simplest one possible 3. http://msdn.microsoft.com/en-us/library/bb386386.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

    I did everything according to sample 3 and when I run the application on the same computer service also runs everything works fine, I get back from service text that application sends to service.

    But when I try the same thing with application that is on some other computer (in the same network (192.168.1.x - service, 192.168.1.y - application) I get unhandled exception:

    I guess it is something with the IP addresses from the machine where I run the application the request is not getting to the computer that is hosting service.

    Could someone help me with this.

    Best regards,

    Greg

    ************** Exception Text **************
    System.InvalidOperationException: Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
       at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
       at System.ServiceModel.ClientBase`1..ctor()
       at WindowsApplication1.ServiceReference1.Service1Client..ctor()
       at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e)

    Friday, May 31, 2013 7:09 AM

Answers

All replies

  • Hi,

    If you want to access that service on another machine, you need publish the service( to IIS for example), you can get the steps to deploy a service in this document: http://msdn.microsoft.com/en-us/library/bb924407.aspx , after publish you can view the service in the browser on another machine with http://ipaddress/.../yourServiceName.svc.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Haixia_XieModerator Thursday, June 6, 2013 9:57 AM
    • Unmarked as answer by Gregec Thursday, June 13, 2013 8:28 AM
    • Marked as answer by Gregec Thursday, June 20, 2013 10:25 AM
    Monday, June 3, 2013 7:28 AM
    Moderator
  • Hi Haixia,

    sorry for my late reply I was trying to do this since the day you posted this answer.

    Let me refresh what I did and what I am trying to do.


    As written in my first post I created wcfservice and application with tutorial under point 3.

    If I press debug on wcf service project it opens wcf test client and wcf service host says the service is being hosted.

    I can then try the application (simple send string and the same string is returned) I can also input

    http://192.168.45.37:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/ link in the browser and it shows the service page.

    If I put the same link to the browser on my other domain computer it also shows the service page (which means that service is accessible trough the network.

    I have two problems I can't resolve:

    • If I copy my WindowsApplication1, which locally works , to my other domain computer and run it, there it crashes.

    Last two strings of crash report : System.InvalidOperationException: Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)


    • My other problem is trying to publish to IIS. I follow the instruction in link you posted but I can't make it work.

    I publish WCFServiceLibrary1 to IIS 7 default web site under name MyWCF.

    But when I put localhost/MyWCF in browser it only shows directory structure (bin, wcfservicelibrary1.service1.svc, web.config) it doesn't show the service page as described above.

    Of course WindowsApplication1 doesn't work either locally or on my other domain computer.

    Any help is very appreciated.

    Thanks,

    Grega

    PS: I unmarked your post as answer just so the thread will not be ignored.






    • Edited by Gregec Thursday, June 13, 2013 8:27 AM
    Thursday, June 13, 2013 8:25 AM
  • Hi,

    I had some progress :)

    As mentioned above publishing to IIS and then testing in my browser didn't work. I found a forum where someone suggested to manually register v4 of framework the localhost/mywcf started working

    c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

    I still cannot access the service from other domain computer: http://192.168.45.37:8080/mywcf/WcfServiceLibrary1.Service1.svc

    Below is service app config file.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="WcfServiceLibrary1.Service1" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
            <host>
              <baseAddresses>
                <add baseAddress = "http://192.168.45.37:8731/MyWCF/" />
              </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
              <!-- 
                  Upon deployment, the following identity element should be removed or replaced to reflect the 
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                  automatically.
              -->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <!-- Metadata Endpoints -->
            <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
            <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="WcfServiceLibrary1.Service1Behavior">
              <!-- To avoid disclosing metadata information, 
              set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="True"/>
              <!-- To receive exception details in faults for debugging purposes, 
              set the value below to true.  Set to false before deployment 
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    

    Best regards,

    Grega

    Thursday, June 13, 2013 11:27 AM
  • Hi all,

    for future reference. To be able to access wcf on IIS from other computer on a domain trough port 8731 i had to bind this port on default web page in IIS.

    I am now working on the first two samples from my start post, but am encountering other issues which I will open separate thread.

    Best regards,

    Greg

    • Marked as answer by Gregec Thursday, June 20, 2013 10:25 AM
    Thursday, June 20, 2013 10:25 AM