CRM插件调用外部Web服务

时间:2015-01-22 16:13:11

标签: c# web-services dynamics-crm-2013

我们在CRM 2013的内部部署,我们正在编写插件来调用外部Web服务。 Web服务正在使用WSHttpBinding。基本上,这个插件将在CRM中创建帐户时调用,然后将信息传递到Web服务。

这是我的代码:

var binding = new WSHttpBinding(SecurityMode.None);
//binding.Security.Mode = WSDualHttpSecurityMode.None;
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
binding.SendTimeout = TimeSpan.FromMinutes(3);
binding.ReceiveTimeout = TimeSpan.FromMinutes(3);
binding.OpenTimeout = TimeSpan.FromMinutes(3);
binding.CloseTimeout = TimeSpan.FromMinutes(3);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
//binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

var address = new EndpointAddress(ea);

ChannelFactory<IPropertyServiceChannel> factory = new ChannelFactory<IPropertyServiceChannel>(binding, address);
IPropertyServiceChannel channel = factory.CreateChannel();

using (var proxy = new PropertyServiceClient(binding, address))
{
    var tid = new Tid { Dtid = "dMaster", Ptid = "pMain" };

    var newProp = new PropertySetup
    {                  
       //setup data

    };

    proxy.CreateProperty(newProp); //this or below isn't working...
    //channel.CreateProperty(newProp); //this is not working
    //channel.Close(); 

但是我不断收到错误消息: &#34;无法处理邮件。这很可能是因为行动&#39; http://tempuri.org/IPropertyService/CreateProperty&#39;不正确或因为邮件包含无效或过期的安全上下文令牌,或者因为绑定之间存在不匹配。如果服务因不活动而中止通道,则安全上下文令牌将无效。要防止服务中止空闲会话,请过早增加服务端点绑定的接收超时。&#34;

非常感谢任何建议。 TIA

0 个答案:

没有答案