2012-01-30 82 views
2

我在VS2010項目中添加了對SOAP服務的引用。我有一個註冊用戶通訊的表單。爲了讓我能夠使用此表單,我必須編輯SharePoint服務器的web.config並添加SOAP綁定。如果我不這樣做,並把它添加到我的項目的app.config中,服務器提供了一個錯誤:SharePoint 2010 - 使用SOAP Web服務

Could not find default endpoint element that references contract 'contractAPI.Soap' in the ServiceModel client configuration section.

我怎樣才能繞過web.config中,使用的app.config來配置SOAP服務或使用C#編程設置此?

回答

2

您可以在您的代碼綁定是這樣的:

internal static WServiceSoapClient CreateWebServiceInstance() 
{ 
    BasicHttpBinding binding = new BasicHttpBinding(); 
    binding.SendTimeout = TimeSpan.FromMinutes(1); 
    binding.OpenTimeout = TimeSpan.FromMinutes(1); 
    binding.CloseTimeout = TimeSpan.FromMinutes(1); 
    binding.ReceiveTimeout = TimeSpan.FromMinutes(10); 
    binding.AllowCookies = false; 
    binding.BypassProxyOnLocal = false; 
    binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; 
    binding.MessageEncoding = WSMessageEncoding.Text; 
    binding.TextEncoding = System.Text.Encoding.UTF8; 
    binding.TransferMode = TransferMode.Buffered; 
    binding.UseDefaultWebProxy = true; 
    return new WServiceSoapClient(binding, new EndpointAddress("http://yourservice.com/service.asmx")); 
} 
+0

我已經試過之前該解決方案,但我仍然得到同樣的錯誤。即使在手動定義這些值之後,WebPart仍會查看web.config。 – Collin 2012-01-30 20:57:23

+0

在我使用Web服務的代碼中,我使用:WServiceSoapClient client = WebServiceHelper.CreateWebServiceInstance()而不是新的WServiceSoapClient(),並且配置文件根本不會被打到,因爲它需要的所有信息都已提供綁定。你可以發佈你的一些代碼嗎? – DavidGouge 2012-01-30 21:07:37

+0

我添加了可用的SOAP配置值以及發佈內容。 'binding.Name =「SoapBinding」; binding.ReaderQuotas.MaxDepth = 32; binding.ReaderQuotas.MaxStringContentLength = 8192; binding.ReaderQuotas.MaxArrayLength = 16384; binding.ReaderQuotas.MaxBytesPerRead = 4096; binding.ReaderQuotas.MaxNameTableCharCount = 16384; binding.MaxBufferSize = 65536; binding.MaxBufferPoolSize = 524288; binding.MaxReceivedMessageSize = 65536; client.ClientCredentials.UserName.UserName =「username」; client.ClientCredentials.UserName.Password =「password」;' – Collin 2012-01-31 15:02:23