這是一個問題,但它不是,它似乎是問題。
您實際上並不需要所有使用您的代碼的項目中的服務引用 - 您需要的僅僅是app.config中的一些信息。具體來說,綁定和端點地址。你可以將它們硬編碼到你的代碼中,然後你應該可以很好地引用它。
最簡單的例子:
var request = new MyServiceRequest { /* set properties here */ };
var client = MyServiceReferenceClient(new BasicHttpBinding(), new EndpointAddress(@"https://my.service.com/path/to/service"));
var channel = client.ChannelFactory.CreateChannel();
var result = channel.MyService(request);
你想設置的BasicHttpBinding
多參數匹配什麼在app.config文件和URL也出來那裏。
請參閱this answer爲什麼默認情況下它不起作用。
編輯:對於你的代碼,你只需用線沿線的東西取代new Account_SSPSoapClient();
:
new Account_SSPSoapClient(new BasicHttpBinding(), new EndpointAddress(@"https://my.service.com/path/to/service"));
其他的一切應該是相同的,但它會使用這些值來代替app.config的值(這是沒有參數)。
看在app.config文件類似:
<bindings>
<basicHttpBinding>
<binding name="LabelRecoveryBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
一切都在對應於您可以在上面創建的BasicHttpBinding
對象上設置屬性 - 大部分是默認值,但您可能想要手動設置一切以保證安全。
同樣,尋找
<client>
<endpoint address="http://153.2.133.60:48010/xoltws_ship/LBRecovery"
binding="basicHttpBinding" bindingConfiguration="LabelRecoveryBinding"
contract="UPSLabelRecoveryService.LabelRecoveryPortType" name="LabelRecoveryPort" />
</client>
,告訴你提供給new EndpointAddress
什麼URL。
你能詳細解釋一下嗎?該代碼段是否進入類庫或引用它的項目? – Logarr 2013-03-13 14:37:14
@記者 - 編輯 - 這有幫助嗎?它在你所在的類庫中(大概)已經在打電話了。 – Bobson 2013-03-13 15:01:13
不是真的......我編輯了這個問題來展示我現在如何調用API的示例。在這種情況下,我看不出如何應用您的方法。 – Logarr 2013-03-13 15:16:04