我正在使用SOAP服务。在asp.net核心项目中作为连接服务。 Soap UI填充响应。但是没有将我的方法填充到asp.net核心中。
我在许多不同的地方搜索过。我检查了一切。但是我找不到解决问题的方法。
var products = response.GetProductListResponse.products
从上面的行返回一个数组。到目前为止,没有问题。一些功能已经完整,但是其中大多数是空白的,我无法提出合理的解决方案。
您可以在下面找到所有示例代码。预先感谢您的帮助。
model binding image! response for .net View image
ConnectedService.Json
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.40203.910",
"ExtendedData": {
"inputs": [
"https://api.n11.com/ws/ProductService.wsdl"
],
"collectionTypes": [
"System.Collections.Generic.List`1",
"System.Collections.Generic.Dictionary`2"
],
"namespaceMappings": [
"*, Soluto.Marketplace.WebServices.N11.Products"
],
"targetFramework": "netcoreapp3.1",
"typeReuseMode": "None"
}
}
请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.n11.com/ws/schemas">
<soapenv:Header/>
<soapenv:Body>
<sch:GetProductListRequest>
<auth>
<appKey>apikey</appKey>
<appSecret>secretKey</appSecret>
</auth>
<pagingData>
<currentPage>0</currentPage>
<pageSize>200</pageSize>
</pagingData>
</sch:GetProductListRequest>
</soapenv:Body>
</soapenv:Envelope>
响应
<env:Body>
<ns3:GetProductListResponse xmlns:ns3="http://www.n11.com/ws/schemas">
<result>
<status>success</status>
</result>
<products>
<product>
<currencyAmount>223.00</currencyAmount>
<currencyType>2</currencyType>
<displayPrice>1766.16</displayPrice>
<isDomestic>false</isDomestic>
<id>453198848</id>
<price>1766.16</price>
<productSellerCode>123156d4sf56sd4f56s</productSellerCode>
<approvalStatus>1</approvalStatus>
<saleStatus>2</saleStatus>
<stockItems>
<stockItem>
<bundle>false</bundle>
<currencyAmount>223.00</currencyAmount>
<displayPrice>1766.16</displayPrice>
<optionPrice>1766.16</optionPrice>
<attributes/>
<id>126907849152</id>
<quantity>150</quantity>
<version>4</version>
</stockItem>
</stockItems>
<subtitle>test ürün 2</subtitle>
<title>Test Ürün</title>
<unitInfo/>
</product>
</products>
<pagingData>
<currentPage>0</currentPage>
<pageSize>100</pageSize>
<totalCount>1</totalCount>
<pageCount>1</pageCount>
</pagingData>
</ns3:GetProductListResponse>
</env:Body>
</env:Envelope>
C#代码
public async Task<IList<ProductBasic>> GetProducts(N11PagingModel n11PagingModel)
{
var authentication = GetAuthentication();
var client = new ProductServicePortClient();
var response = await client.GetProductListAsync(new GetProductListRequest { auth = authentication, pagingData = n11PagingModel.Map<RequestPagingData>() });
var result = response.GetProductListResponse.result;
if (result.status == "success")
{
var products = response.GetProductListResponse.products?.ToList();
return products;
}
else
{
return null;
}
}
答案 0 :(得分:1)
更改:
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
收件人
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Document, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Literal)]
答案 1 :(得分:0)
我在这里在黑暗中拍照,但我认为问题在于您试图通过两次调用以下命令来读取相同的响应流两次:
response.GetProductListResponse
代替尝试:
public async Task<IList<ProductBasic>> GetProducts(N11PagingModel n11PagingModel)
{
var authentication = GetAuthentication();
var client = new ProductServicePortClient();
var response = await client.GetProductListAsync(new GetProductListRequest { auth = authentication, pagingData = n11PagingModel.Map<RequestPagingData>() });
var responseObject = response.GetProductListResponse;
if (responseObject.result.status == "success")
{
var products = responseObject.products?.ToList();
return products;
}
else
{
return null;
}
}