GVKun编程网logo

SOAP Web服务是否仅支持“ POST” http方法(soap请求webservice)

31

关于SOAPWeb服务是否仅支持“POST”http方法和soap请求webservice的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.net–Web服务使用ksoap方法从应用程序接

关于SOAP Web服务是否仅支持“ POST” http方法soap请求webservice的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.net – Web服务使用ksoap方法从应用程序接收空参数、asp.net-web-api – 请求的资源不支持http方法“PUT”、C#通过WebClient/HttpWebRequest实现http的post/get方法、CentOS 平台,使用 httpd 2.2 和 httpd 2.4 部署 web服务器等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

SOAP Web服务是否仅支持“ POST” http方法(soap请求webservice)

SOAP Web服务是否仅支持“ POST” http方法(soap请求webservice)

我在一次采访中遇到了这个问题,所以能否请您说一下SOAP Web服务是否仅支持“ POST” http方法,或者在服务器端是否有某种方法可以接受其他方法?

答案1

小编典典

我一直使用POST,但是根据W3C标准,SOAP支持POST和GET方法。

编辑:经过一些研究,似乎并不完全正确。这是 理论上 可能使用GET因为POST和GET是可用于通过HTTP传输协议和SOAP的HTTP方法。

但是,正如您所知,GET将请求包含在查询字符串中。SOAP请求(XML消息)通常过于复杂和冗长,无法包含在查询字符串中,因此几乎每个实现(例如JAX-WS)仅支持POST。

.net – Web服务使用ksoap方法从应用程序接收空参数

.net – Web服务使用ksoap方法从应用程序接收空参数

我已经看过讨论这个的话题,但似乎没有人发布解决方案.目前,我正在测试传递参数到我的.Net Web服务.当参数到达Web服务时,它会添加一个额外的字符串,然后将其返回给我的应用程序;但我正在返回的是字符串消息,而不是我传递的参数.我的网络服务或肥皂方法有问题吗?

肥皂:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("A", "workowr");


    SoapSerializationEnvelope envelope =
        new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setoutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);    
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
            //SoapObject result = (SoapObject)envelope.getResponse();       
            String resultData = result.toString();
            testTV.setText(resultData);

        }
        catch(Exception e)
        {
            testTV.setText(e.getMessage());
        }

这是我简单的.Net网络服务:

Public Function getRegInfo(ByVal A As String) As String

Return A + “String message”

End Function

我将不胜感激任何帮助.

解决方法:

对我有用的是改变我的.Net webservice和我的应用程序中的命名空间URL.

例如,我有:

“http://www.example.com/webservices/”

我改为:

“example.com/webservices/”

它工作得很好.

试一试.

asp.net-web-api – 请求的资源不支持http方法“PUT”

asp.net-web-api – 请求的资源不支持http方法“PUT”

我在我的Web API(MVC 4)中使用AttributeRouting.

为什么这样做?

[AcceptVerbs("PUT")]
    [PUT("api/v1/tokens/current")]
    public MemoryToken Updatetoken([FromBody] Devicetokenviewmodel viewmodel)
    {...}

这一个不是吗?

[PUT("api/v1/tokens/current")]
    public MemoryToken Updatetoken([FromBody] Devicetokenviewmodel viewmodel)
    {...}

错误消息:请求的资源不支持http方法“PUT”.
为什么我必须明确接受PUT动词?

我只是感到困惑,因为与POST类似的东西工作正常(我不必指定接受的动词):

[POST("api/v1/tokens")]
 public MemoryToken Createtoken()
 {...}

从其他各种帖子我相信它与我的web.config中的设置有关. Web服务器部分目前看起来像这样:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptprocessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,OPTIONS" modules="IsapiModule" scriptprocessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  <add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler,AttributeRouting.Web" />
</handlers>

我尝试过删除WebDav和其他东西.但到目前为止没有任何工作(除非在注释中明确允许PUT动词).

哦,我正在使用Visual Studios内置的开发服务器.

多谢你们!

解决方法

在这个 link中,如果没有任何动作匹配,它们将POST方法描述为默认方法.这就是为什么它仍然适用于没有HttpPost属性的Createtoken()方法.

>您可以使用以下属性指定HTTP方法:AcceptVerbs,HttpDelete,HttpGet,HttpHead,HttpOptions,HttpPatch,HttpPost或HttpPut.>否则,如果控制器方法的名称以“Get”,“Post”,“Put”,“Delete”,“Head”,“Options”或“Patch”开头,那么按照惯例,该操作支持该HTTP方法.>如果不是上述方法,则该方法支持POST.

C#通过WebClient/HttpWebRequest实现http的post/get方法

C#通过WebClient/HttpWebRequest实现http的post/get方法

//body是要传递的参数,格式"roleId=1&uid=2"
//post的cotentType填写:
//"application/x-www-form-urlencoded"
//soap填写:"text/xml; charset=utf-8"
    public static string PostHttp(string url, string body, string contentType)
    {
        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

        httpWebRequest.ContentType = contentType;
        httpWebRequest.Method = "POST";
        httpWebRequest.Timeout = 20000;

        byte[] btBodys = Encoding.UTF8.GetBytes(body);
        httpWebRequest.ContentLength = btBodys.Length;
        httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);

        HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
        string responseContent = streamReader.ReadToEnd();

        httpWebResponse.Close();
        streamReader.Close();
        httpWebRequest.Abort();
        httpWebResponse.Close();

        return responseContent;
    }

POST方法(httpWebRequest)
public static string GetHttp(string url, HttpContext httpContext)
    {
        string queryString = "?";

        foreach (string key in httpContext.Request.QueryString.AllKeys)
        {
            queryString += key + "=" + httpContext.Request.QueryString[key] + "&";
        }

        queryString = queryString.Substring(0, queryString.Length - 1);

        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url + queryString);

        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Method = "GET";
        httpWebRequest.Timeout = 20000;

        //byte[] btBodys = Encoding.UTF8.GetBytes(body);
        //httpWebRequest.ContentLength = btBodys.Length;
        //httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);

        HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
        string responseContent = streamReader.ReadToEnd();

        httpWebResponse.Close();
        streamReader.Close();

        return responseContent;
    }

Get方法(HttpWebRequest)
/// <summary>
        /// 通过 WebRequest/WebResponse 类访问远程地址并返回结果,需要Basic认证;
        /// 调用端自己处理异常
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="timeout">访问超时时间,单位毫秒;如果不设置超时时间,传入0</param>
        /// <param name="encoding">如果不知道具体的编码,传入null</param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string Request_WebRequest(string uri, int timeout, Encoding encoding, string username, string password)
        {
            string result = string.Empty;

            WebRequest request = WebRequest.Create(new Uri(uri));

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                request.Credentials = GetCredentialCache(uri, username, password);
                request.Headers.Add("Authorization", GetAuthorization(username, password));
            }

            if (timeout > 0)
                request.Timeout = timeout;

            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            StreamReader sr = encoding == null ? new StreamReader(stream) : new StreamReader(stream, encoding);

            result = sr.ReadToEnd();

            sr.Close();
            stream.Close();

            return result;
        }

        #region # 生成 Http Basic 访问凭证 #

        private static CredentialCache GetCredentialCache(string uri, string username, string password)
        {
            string authorization = string.Format("{0}:{1}", username, password);

            CredentialCache credCache = new CredentialCache();
            credCache.Add(new Uri(uri), "Basic", new NetworkCredential(username, password));

            return credCache;
        }

        private static string GetAuthorization(string username, string password)
        {
            string authorization = string.Format("{0}:{1}", username, password);

            return "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(authorization));
        }

        #endregion

basic验证的WebRequest/WebResponse

 

CentOS 平台,使用 httpd 2.2 和 httpd 2.4 部署 web服务器

CentOS 平台,使用 httpd 2.2 和 httpd 2.4 部署 web服务器

1、查看当前的系统

uname -r

cat /etc/redhat-release

2、通过rpm 安装httpd

yum install httpd

a、安装完成后,参看相应的配置文件。

/etc/httpd/conf/httpd.conf # 主配置文件。

A、修改参数

Listen [IP:]port # 可以出现多次。

ServerName www.njjn.com:80

DoucumentRoot /var/www/html # 文档主目录

NameVirtualHost 192.168.10.16:80 # 配置虚拟机是必须配置的参数,【仅在CentOS 6 可用,CentOS 7 以废除。】

<Directory "/var/www/html"> # 安全的访问控制。

Options None

AllowOverride None

Order allow,deny

Allow from [all | 192.168 | 192.168.0.0/16]

# 基于主机的访问控制

AuthType basic

AuthName "only for root"

AuthUserFile "/etc/httpd/conf.d/.htpasswd"

Require valid-user # 基于用户的访问控制

</Directory>

B、生成用户的密码文件

htpasswd -c -m -b /etc/httpd/conf.d/.htpasswd redhat redhat

-c : 第一次创建时使用

-b : 通过命令行给密码

-m : 密码通过MD5加密。

C、查看当前服务器加载的模块

ps aux # 查看系统运行在哪个MPM模式下

httpd -l # 查看核心模块

-M # 查看所有的模块

-t # 配置文件语法检查。


/etc/httpd/conf.d/ # 辅助配置文件。

/etc/sysconfig/httpd # MPM 信息。

b、添加到开机启动。

chkconfig --add httpd

chkconfig httpd on

service httpd start

3、通过浏览器查看

问题:服务器端要关闭防火墙和selinux

iptables -F

setenforce 0 | permissive

4、配置虚拟主机 【based-name】

a、配置主配置文件里面的参数。

/etc/httpd/conf/httpd.conf 添加 NameVirtualHost 192.168.10.15:80

b、在/etc/httpd/conf.d/ 目录里面创建虚拟和主机的配置文件。

vi vhost-1.conf

<VirtualHost 192.168.10.15:80> # 要和NameVirtualHost 相同。

ServerName "www.njjn.com"

DocumentRoot "/data/vhosts/www1"

CustomLog "logs/www1-access-log" combined # 相对路径,相对与 ServerRoot ,配置文件的路径。 /etc/httpd/logs 是 目录的软连链接。

ErrorLog "logs/www1-error-log"


# 如果在CentOS 7上,需要显示的给予授权。因为它默认是拒绝的。和 6 相反。

<Directory "/data/vhosts/www1"> # 对虚拟的主机设置访问控制

Options None

AllowOverride None

Require [not] ip 192.168 # 仅 192.168.0.0 网段的可以访问。

Require [not] host www.njjn.com # 使用一个就可以。

Requireall granted # 所有人都可以访问

</Directory>

<Location /server-status> # 查看服务器的运行状态的信息。

SetHandler server-status

AuthType basic

AuthName "only for limit user"

AuthUserFile "/etc/httpd/conf.d/.htpasswd"

Require valid-user | user1 user2

</Location> # 仅认证过的账户可以访问,

</VirtualHost>

5、配置 https

a、创建私有的CA

cd /etc/pki/CA

(umask 066; openssl genrsa -out private/cakey.pem 2048) # 私钥必须是600权限,

openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650

生成自签整数。

openssl x509 -in private/cakey.pem -text # 大约是,查看整数信息。

openssl rsautl -in private/cakey.pem -out capub.pem -pubout

b、给应用程序生成,

(umask 066; openssl genrsa -out httpd.key 1024)

openssl req -new -key httpd.key -out httpd.csr -days 3650

scp httpd.csr root@172.16.17.18:/tmp/

d、CA 给予授权

openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 3650

scp 传给客户端。

e、客户端收到后,

mkdir /etc/httpd/ssl

把文件放到上面的目录。

f、客户端安装,https 需要的 mod_ssl rpm 包

此包会在,/etc/httpd/conf.d/目录,创建ssl.conf 文件。

编辑参数。

ServerName

DocumentRoot

SSLCertificateFile "/etc/httpd/ssl/httpd.crt" # 整数文件, httpd.crt

SSLCertificateKeyFile "/etc/httpd/ssl/httpd.key" # 本机的私钥文件。

重启服务:service httpd start

通过浏览器访问,要把私有CA的私钥导入浏览器,不然会提示证书无效。不导入也不影响使用。


6、安装MysqL,mariadb

yum install MysqL-server | mariadb-server

a、配置参数

vi /etc/my.cnf

innodb_file_per_table=ON # 每个表对应一个文件。

skip_name_resolve=ON # 跳过名称解析。CentOS 6 【无效】。

7、安装PHP,PHP-zts,PHP-MysqL

yum install PHP

a、会生成,libPHP5.so 库,可以和 prefork 相匹配。

b、libPHP5-zts.so 可以和 worker,event 想匹配,所在包是PHP-zts

这两种都是,httpd的模块的形式工作。

Client request index.PHP -> Server httpd receive,启用,PHP进程,进行处理。

PHP-MysqL : 是为PHP 和MysqL通信提供驱动。

编辑及页面,/data/vhosts/www1/index.PHP

vi ~~

<?PHP

PHPinfo();

?>

客户成功,锁屏配置成功。


httpd 2.4: 特性

1、DSO: dynamic share object,支持动态的模块编辑,

2、毫秒级的KeepAlive 500ms 持久连接。

3、MPM event 可以在生产中使用。

4、性能提升,节约内存等。


apr: apache portable runtime ,httpd跨平台的基础。

apr

apr-util

apr-iconv

关于SOAP Web服务是否仅支持“ POST” http方法soap请求webservice的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.net – Web服务使用ksoap方法从应用程序接收空参数、asp.net-web-api – 请求的资源不支持http方法“PUT”、C#通过WebClient/HttpWebRequest实现http的post/get方法、CentOS 平台,使用 httpd 2.2 和 httpd 2.4 部署 web服务器等相关知识的信息别忘了在本站进行查找喔。

本文标签: