C# 为 ebay 上传到 LMS 配置网络套接字绑定 [英] C# Configuring web socket bindings for ebay uploads to LMS

查看:17
本文介绍了C# 为 ebay 上传到 LMS 配置网络套接字绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在尝试使其正常工作,但似乎无法正确完成.我需要为 ebay LMS 创建一个 Web 套接字 http 绑定.

Ok so I'm trying to get this working but can't seem to get it right. I need to create a web socket http binding for ebay LMS.

这是我的网络配置:

<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>

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

This is my code to create the upload request:

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 来自这个链接 在底部附近你会看到 BDXSmaple.zip包含代码.

The BulkDataExchangeService comes from this link Down near the bottom you will see BDXSmaple.zip which contains the code.

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

The problem I'm having is with the service contract contract="BulkDataExchangeServicePort"

如果我将鼠标悬停在合同上,则会出现错误合同属性无效 - BulkDataExchangeServicePort 的值是根据它的数据类型 clientContractType 无效 -枚举约束失败"

If I hover over the contract it gives me the error "The contract attribute is invalid - The value BulkDataExchangeServicePort is invalid according to it's data type clientContractType - The enumeration constraint failed"

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

In the debug window I get this message:

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

Exception thrown: 'System.InvalidOperationException' in System.ServiceModel.dll Could not find endpoint element with name 'BulkDataExchangeService' and contract 'BulkDataExchangeServicePort' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

我真的不确定服务合同哪里出了问题.任何人都可以帮忙.干杯

I'm really not sure where I'm goign wrong with the service contract. can anyone help. Cheers

推荐答案

好的,现在我知道发生了什么,我正在使用 nopCommerce atm 作为 Visual Studio 中的解决方案.

Ok so I now know what was going on, I'm working with nopCommerce atm as a solution in visual studio.

我所做的是将端点添加到错误的配置文件中.

What I was doing was adding the endpoint to the wrong config file.

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

Once it was moved from nop.Admin web.config to nop.Web web.config it worked. Hope this might help someone else :)

这篇关于C# 为 ebay 上传到 LMS 配置网络套接字绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆