标签: webservice-client

如何将UsernameToken添加到Web服务代理类的RequestSoapContext属性

我有一个我引用的服务,它创建了一个代理类"MyWebService".但是当我使用该类时,它的对象似乎没有RequestSoapContext属性.以下是我期望使用该服务的方式:

            MyWebService objWS = new MyWebService();
            UsernameToken token = new UsernameToken("User","Password", PasswordOption.SendPlainText);
            objWS.RequestSoapContext.Security.Timestamp.TtlInSeconds = 60;
            objWS.RequestSoapContext.Security.Tokens.Add(token);
            objWS.RequestSoapContext.Security.MustUnderstand = false;
Run Code Online (Sandbox Code Playgroud)

是否需要对生成的代理类进行一些配置/修改,以便我可以在代理类中获取RequestSoapContext,或者我是否需要在服务端执行某些操作?

谢谢你的时间...

.net wcf webservice-client

3
推荐指数
1
解决办法
5615
查看次数

使用pyCurl发布问题

我正在尝试使用CURL将文件发布到Web服务(这是我需要使用的,所以我不能采取扭曲或其他东西).问题是,当使用pyCurl时,web服务不会收到我正在发送的文件,如文件底部注释的情况.我在pyCurl脚本中做错了什么?任何想法?

非常感谢你.

import pycurl
import os

headers = [ "Content-Type: text/xml; charset: UTF-8; " ]
url = "http://myurl/webservice.wsdl"
class FileReader:
    def __init__(self, fp):
        self.fp = fp
    def read_callback(self, size):
        text = self.fp.read(size)
        text = text.replace('\n', '')
        text = text.replace('\r', '')
        text = text.replace('\t', '')
        text = text.strip()
        return text

c = pycurl.Curl()
filename = 'my.xml'
fh = FileReader(open(filename, 'r'))

filesize = os.path.getsize(filename)
c.setopt(c.URL, url)
c.setopt(c.POST, 1)
c.setopt(c.HTTPHEADER, headers)
c.setopt(c.READFUNCTION , fh.read_callback)
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTP_VERSION, c.CURL_HTTP_VERSION_1_0)
c.perform()
c.close()
# This is …
Run Code Online (Sandbox Code Playgroud)

python webservice-client pycurl

3
推荐指数
1
解决办法
2880
查看次数

如何使用jquery发送int类型参数

我正在构建一个使用jquery与网页通信的Web服务.我想构建我的webservice,因此它是类型安全的,无需在服务器端执行转换.

如何从客户端发出ajax调用,使用jquery到期望int值参数的服务器.

编辑:我明白这是不可能的.我用c#编写服务器端.目前,Web服务支持来自客户端(js)和其他实用程序(其他c#程序)的调用.我目前可以想到的最简单的解决方案是复制方法并将其签名更改为字符串,然后转换数据类型并调用方法,这次使用正确的数据类型.

是否有任何.net 4属性可以装饰我自动执行此操作的方法?

谢谢

ajax jquery webservice-client

3
推荐指数
1
解决办法
2万
查看次数

WCF 4.0与PHP 5客户端

我正在尝试为WCF Web服务创建一个PHP客户端.但是当我调用服务的功能时,我得到了一些错误.

App.config中

<system.serviceModel>
<services>
  <service behaviorConfiguration="MyServiceBehavior"
           name="GSC.Wcf.Services.CartService">
    <endpoint address=""
              binding="basicHttpBinding"
              contract="GSC.Wcf.Services.ICartService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding"
              contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8731/CartService" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

功能:

> public int Addiere(int a, int b)
        {
            return a + b;
        }
Run Code Online (Sandbox Code Playgroud)

PHP请求:

> $client = new SoapClient("http://localhost:8731/CartService?wsdl");
>
> $result = $client->Addiere(2,4);
Run Code Online (Sandbox Code Playgroud)

对于这些功能我得到一个像这样的错误:

"Uncaught SoapFault异常:[a:DeserializationFailed] Formatierer格式化程序在消息去除期间发布了异常:无法反序列化消息的请求主体用于操作"Addiere".结束元素"Body"aus命名空间预计会出现"http://schemas.xmlsoap.org/soap/envelope/".发现是Namespace""的元素"param1".

在德国:

致命错误:未被捕获的SoapFault异常:[a:DeserializationFailed] Der Formatierer hat beim Deserialisieren …

php wcf webservice-client

3
推荐指数
1
解决办法
4199
查看次数

无法通过HTTPS调用Web服务

我正在开发一个与Web服务通信的.Net应用程序来获取一些数据..Net应用程序和Web服务之间的连接是通过HTTPS完成的.当我从.Net应用程序调用Web服务时,我得到以下堆栈跟踪:

    System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at …
Run Code Online (Sandbox Code Playgroud)

.net https certificate webservice-client

3
推荐指数
1
解决办法
9148
查看次数

从宁静的Java客户端获取JSON

我正在使用REST(Jersey 1.8)开发Web服务.目前我正在使用XML在Java客户端和服务器之间进行通信.

我需要将其更改为JSON:我该怎么做?我有大量来自NetBeans的自动生成代码,并且不知道该做什么以及如何做.在测试服务时,它显示JSON数据.我无法做的是在我的main方法中处理它. 在此输入图像描述

这些是我遵循的教程

我的Java客户端main方法:

public class SOATestClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PersonJerseyClient client = new PersonJerseyClient();
        ClientResponse response = client.findAll_XML(ClientResponse.class);


        GenericType<List<Person>> genericType = new GenericType<List<Person>>() {
        };
// Returns an ArrayList of Players from the web service
        List<Person> data = new ArrayList<Person>();
        data = (response.getEntity(genericType));
        System.out.println("Retreiving and Displaying Players Details");
        for (Person person : data) {
            System.out.println("FirstName: " + person.getName()); …
Run Code Online (Sandbox Code Playgroud)

java rest soa json webservice-client

3
推荐指数
1
解决办法
2万
查看次数

如何将消息上下文头添加到apache axis 2 Java

我正在从事网络服务.我想知道如何在JAX-WS类型的Web服务中向SOAP请求添加标头.

考虑我的头像这样.

    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("Username", Collections.singletonList("aaaa"));
    headers.put("Password", Collections.singletonList("aaaa"));
Run Code Online (Sandbox Code Playgroud)

我的客户端类中有stub对象.我正在使用Apache Axis 2.所有类都是自动生成的.

SimpleSTub stub = new Simplestub();
Run Code Online (Sandbox Code Playgroud)

我想在客户端添加此标头信息.

MessageContext.HTTP_REQUEST_HEADERS, headers
Run Code Online (Sandbox Code Playgroud)

编辑

在普通类中的实际实现发现为

private static final String WS_URL ="http:// localhost:9999/ws/hello?wsdl";

public static void main(String [] args)throws Exception {

URL url =新URL(WS_URL); QName qname = new QName("http://ws.mkyong.com/","HelloWorldImplService");

Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);

/*******************UserName & Password ******************************/
Map<String, Object> req_ctx = ((BindingProvider)hello).getRequestContext();
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);

Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("mkyong"));
headers.put("Password", Collections.singletonList("password")); …
Run Code Online (Sandbox Code Playgroud)

java axis2 web-services jax-ws webservice-client

3
推荐指数
1
解决办法
1万
查看次数

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException

以前,我可以成功地向Web服务发送请求并接收响应,但它现在返回以下异常.基于其他答案,我需要更新证书,但我需要知道为什么我现在收到此例外.另一个问题是,我可以找到我的java_home的地址,但我无法续订证书.

例外:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
Run Code Online (Sandbox Code Playgroud)

URI uri = new URI("https", "xml.example.com", "/service/ServiceRequest.do", 
                           "serverName=www.example.com&xml=" 
                           ...
                           +" ", null);

            URL page = uri.toURL();
            HttpsURLConnection conn = (HttpsURLConnection) page.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.connect();
Run Code Online (Sandbox Code Playgroud)

java ssl webservice-client

3
推荐指数
1
解决办法
1万
查看次数

必须在调用 send 方法之前设置 Web 服务错误路径属性

必须在调用 send 方法之前设置 path 属性

这个错误的原因是什么?

谢谢

asp.net web-services webservice-client web

3
推荐指数
1
解决办法
5354
查看次数

如何在c#中使用Rest Web服务

我写了一个web服务,在浏览器启动时工作正常.我在这个webservice中传递一个客户端ID,然后返回一个包含客户端名称的字符串,我们通过这样的字符串:http://prntscr.com/8c1g9z

我创建服务的代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace RESTService.Lib
{
    [ServiceContract(Name = "RESTDemoServices")]
    public interface IRESTDemoServices
    {
        [OperationContract]
        [WebGet(UriTemplate = "/Client/{id}", BodyStyle = WebMessageBodyStyle.Bare)]
        string GetClientNameById(string Id);
    }

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class RestDemoServices:IRESTDemoServices
    {
        public string GetClientNameById(string Id)
        {
            return ("Le nom de client est Jack et id est : " +Id);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但我无法消耗它.我的代码是:

using System; …
Run Code Online (Sandbox Code Playgroud)

c# rest web-services webservice-client webservices-client

3
推荐指数
1
解决办法
6万
查看次数