更改端点时出现C#WCF错误

时间:2016-04-05 20:06:19

标签: c# web-services wcf

我正在做的服务只是为了测试和学习, 但我正在尝试更改URL端点并返回错误

n: There was no endpoint listening at http://servername:8732/TestService/ that could accept the message. This is often caused by an incorrect address or SOAP action. 

那是我的代码:

private void button1_Click(object sender, EventArgs e)
    {

            var myBinding = new BasicHttpBinding();
            myBinding.Security.Mode = BasicHttpSecurityMode.None;
            var myEndPointAdress = new EndpointAddress("http://servername:8732/TestService/");
            MyCalculatorServiceClient service = new MyCalculatorServiceClient(myBinding, myEndPointAdress);

            MessageBox.Show(Convert.ToString(service.soma(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text))));

    }

App.config“已编辑”:

           <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
        </startup>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IMyCalculatorService" />
                </basicHttpBinding>
            </bindings>
            <client>
              <endpoint address="http://servername:8732/TestService/"
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyCalculatorService"
                  contract="ServiceReference1.IMyCalculatorService" name="BasicHttpBinding_IMyCalculatorService">
                <identity>
                  <dns value="localhost" />
                </identity>
              </endpoint>
            </client>
        </system.serviceModel>
    </configuration>

0 个答案:

没有答案