错误:
在 ServiceModel 客户端配置部分中找不到引用合同“ICalculatorDuplex”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。
参考链接:http: //msdn.microsoft.com/en-us/library/ms735103.aspx
using System;
using System.ServiceModel;
namespace Microsoft.ServiceModel.Samples
{
// The service contract is defined in generatedClient.cs, generated from the service by the svcutil tool.
// Define class which implements callback interface of duplex contract
public class CallbackHandler : ICalculatorDuplexCallback
{
public void Equals(double result)
{
Console.WriteLine("Equals({0})", result);
}
public void Equation(string eqn)
{
Console.WriteLine("Equation({0})", eqn);
}
}
class Client
{
static void Main()
{
// Construct InstanceContext to handle messages on callback interface
InstanceContext instanceContext = new InstanceContext(new CallbackHandler());
// Create a client with given client endpoint configuration
CalculatorDuplexClient client = new CalculatorDuplexClient(instanceContext);
// Console.WriteLine("Press to terminate client once the output is displayed.");
// Console.WriteLine();
// Call the AddTo service operation.
double value = 100.00D;
client.AddTo(value);
// Call the SubtractFrom service operation.
value = 50.00D;
client.SubtractFrom(value);
// Call the MultiplyBy service operation.
value = 17.65D;
client.MultiplyBy(value);
// Call the DivideBy service operation.
value = 2.00D;
client.DivideBy(value);
// Complete equation
client.Clear();
Console.ReadLine();
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
}
}
}
客户端配置:
<system.serviceModel>
<client>
<endpoint address="http://196.9.200.26:8000/ServiceModelSamples/service"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_ICalculatorDuplex"
contract="ServiceReference1.ICalculatorDuplex" name="WSDualHttpBinding_ICalculatorDuplex">
<identity>
<servicePrincipalName value="host/ln-pun-026.imgpoint.com" />
</identity>
</endpoint>
</client>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_ICalculatorDuplex" useDefaultWebProxy="true" bypassProxyOnLocal="false" clientBaseAddress="http://196.9.200.26:8000/myClient/" >
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="None"/>
</binding>
</wsDualHttpBinding>
</bindings>
</system.serviceModel>