如何以二进制编码格式发送WCF请求?

时间:2018-03-25 22:53:44

标签: wcf soap binary

在发送针对WCF服务的请求时需要帮助。该服务具有自定义绑定。该请求需要二进制编码格式。

我收到以下错误 无法处理消息,因为内容类型'application / xml'不是预期类型'application / soap + msbin1'。

public static void Test(string username, string password)
    {
            using (var client = new HttpClient(new HttpClientHandler()))
            {
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(connecturi),
                    Method = HttpMethod.Post
                };
                var soapRequest = new AuthenticateUserRequest
                {
                    Username = username,
                    PasswordHash = Convert.ToBase64String(Encoding.UTF8.GetBytes(password))
                };

                request.Content = new StringContent(SoapRequestToString(soapRequest), Encoding.UTF8, "application/xml");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");
                request.Headers.Add("SOAPAction", "http://tempuri.org/IDataService/AuthenticateUser");

                HttpResponseMessage response = client.SendAsync(request).Result;
            }
    }

0 个答案:

没有答案