2

Ive been experimenting with WCF and added a DataContract to my server and updated a ServiceContract. When the ServiceReference was first added to the client, i was running them both on the same pc, so i used localhost. Ive now tried to connect 2 pc's via an ethernet cable and update the service reference that way. Ive set the servers ip address on the lan to 192.168.10.10 . The following code is executed when a button is clicked on the servers form.

private void btnCommenceService_Click(object sender, EventArgs e)
    {
        host = new ServiceHost((typeof(Service)), new Uri[] { new Uri("http://localhost:9000")});   
        host.AddServiceEndpoint(typeof(IServices),
            new WSDualHttpBinding(),
            "ServerService");

        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
        host.Description.Behaviors.Add(smb);

        host.Open();
        txtStatus.Text = "Service is open.";
    }

Ive turned the firewall off on both pc's and have sucessfully ping'd the address "http://192.168.10.10" from the client pc. Ive managed to access some random webpage as well if i type that into my browser.

In the client, if i click on my solution and select "Add Service Reference" and type in

"http://192.168.10.10" "http://192.168.10.10:9000" "http://192.168.10.10:9000/ServerService"

All of them come back with some form of error, usually something along the following lines:

The document at the url http://192.168.10.10:9000/ was not recognised as a known document type.
The error message for each known type may help u fix the problem:
-Report from 'XML Schema' is The document format is not recognised(the content type is 'text/html;charset=utf-8').'.
Report from DISCO Document is There was an error downloading `'http://localhost:9000/?disco'.'.` 
Unable to connect to the remote server. 
No connection could be made because the target machine actively refused it 127.0.0.1:9000
etc

Anyone got some pointers as to why its not working over the LAN yet i can access and ping the address?

4

3 回答 3

1

try to change your binding security configuration like this

WSDualHttpBinding wsDualBinding= new WSDualHttpBinding();
wsDualBinding.Security.Mode = WSDualHttpSecurityMode.None;
wsDualBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;

then add service endpoint

host.AddServiceEndpoint(typeof(IServices),wsDualBinding,"ServerService");

Hopes it's useful

于 2013-05-13T14:18:01.263 回答
1

You've connected the 2 pc's directly via ethernet. Are you using a cross-over cable? Are the 2 pc's in the same subnet mask? E.g. 255.255.255.0?

于 2013-05-13T15:01:33.490 回答
0

Finally got it working but i chose to restart the entire Server project again. Ive listed below all the things i did differently, some of them may have been issues, others may not have been.

  1. Created a wcf service library rather than trying to just use a winforms program for everything. Once the Service library was complete, i referenced it in my winforms application + copied the code which was in its app.config into the winforms app.config.

  2. Pay particular attention to the base address and the endpoint addresses as you need to add both of them together to then connect to that end point from the Client.

  3. As mentioned by User1467261, I made sure i could ping both ways. I had to go into control pannel->..-> network connections select LAN -> properties -> ipv4 option and then specify a unique IP address on both PC's. (Im guess alot of ppl will already know this but i didnt know how to do this.)

  4. As Feras Salim stated, both security settings were left as default as i just created a new user on my laptop with the same username and password as the other computer.

  5. Client side, i used Add Service Reference. Im not too sure what the mex end point is used for but i just connected to the base address and it updated my app.config file client side. Remember to include a using statement for the namespace you specified when adding the service reference.

  6. Server side, remember to use properties and not fields on a custom class.

Thanks very much to Feras Salim, User1467261 for your help.

于 2013-05-15T08:02:08.737 回答