C#配置ebay上传到LMS的

时间:2018-01-21 22:12:17

标签: c# .net sockets wcf

好的,所以我试图让这个工作起来,但似乎无法做到这一点。 我需要为ebay LMS创建一个Web套接字http绑定。

这是我的网络配置:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="BulkDataExchangeService" closeTimeout="00:01:00"
       openTimeout="00:01:00" receiveTimeout="00:10:00"
       sendTimeout="00:01:00" bypassProxyOnLocal="false"
       transactionFlow="false" hostNameComparisonMode="StrongWildcard"
       maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
       messageEncoding="Text" textEncoding="utf-8"
       useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192"
          maxArrayLength="16384" maxBytesPerRead="4096"
          maxNameTableCharCount="2147483647" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
          enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows"
            proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows"
            negotiateServiceCredential="true" algorithmSuite="Default"
            establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="https://webservices.sandbox.ebay.com/BulkDataExchangeService"
    binding="wsHttpBinding" bindingConfiguration="BulkDataExchangeService"
    contract="BulkDataExchangeServicePort" name="BulkDataExchangeService">
    <identity>
      <userPrincipalName value="machine\user" />
    </identity>
  </endpoint>
</client>
</system.serviceModel>

这是我创建上传请求的代码:

private void CreateUploadJobEbay()
    {
        var ebayAuthTokenSetting = _settingService.GetSettingByKey(
                            "ebaysetting.authtoken", "");

        //EndpointAddress endpoint = new EndpointAddress("https://webservices.sandbox.ebay.com/BulkDataExchangeService");

        BulkDataExchangeServicePortClient client = new BulkDataExchangeServicePortClient("BulkDataExchangeService");

        using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
        {
            HttpRequestMessageProperty httpRequest = new HttpRequestMessageProperty();

            OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest);

            //Add the request headers
            httpRequest.Headers.Add("X-EBAY-SOA-SECURITY-TOKEN", ebayAuthTokenSetting);
            httpRequest.Headers.Add("X-EBAY-SOA-SERVICE-NAME", "BulkDataExchangeService");
            httpRequest.Headers.Add("X-EBAY-SOA-SERVICE-VERSION", "1.0.0");
            httpRequest.Headers.Add("X-EBAY-SOA-MESSAGE-PROTOCOL", "SOAP12");
            httpRequest.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "createUploadJob");

            //Create the request
            CreateUploadJobRequest req = new CreateUploadJobRequest();

            //Supply additional parameters

            //The UUID must be unique. Once used, you can't use it again

            req.UUID = System.Guid.NewGuid().ToString();

            //Specify job type

            req.uploadJobType = "AddFixedPriceItem";

            req.fileType = FileType.XML;

            //Get the response

            CreateUploadJobResponse resp = client.createUploadJob(req);

            Debug.WriteLine("resp = " + resp);
        }
    }

BulkDataExchangeService来自this link靠近底部,您将看到包含代码的BDXSmaple.zip。

我遇到的问题是服务合同contract="BulkDataExchangeServicePort"

  

如果我将鼠标悬停在合同上,它会给我错误&#34;合同   属性无效 - BulkDataExchangeServicePort的值为   根据它的数据类型clientContractType - 无效   枚举约束失败&#34;

在调试窗口中,我收到此消息:

  

抛出异常:&#39; System.InvalidOperationException&#39;在   System.ServiceModel.dll找不到具有名称的端点元素   &#39; BulkDataExchangeService&#39;和合同&#39; BulkDataExchangeServicePort&#39;   在ServiceModel客户端配置部分中。这可能是   因为没有找到您的应用程序的配置文件,或   因为在。中找不到与此名称匹配的端点元素   客户元素。

我真的不确定我在服务合同上的错误。有谁可以帮忙。干杯

1 个答案:

答案 0 :(得分:0)

好的,我现在知道发生了什么,我和nopCommerce atm合作,作为visual studio的解决方案。

我正在做的是将端点添加到错误的配置文件中。

一旦它从nop.Admin web.config移动到nop.Web web.config就可以了。 希望这可以帮助别人:)