PostMan请求Web Service接口

在这里插入图片描述

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xxx="http://tempuri.org/xxx.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
 <soapenv:Header></soapenv:Header>
 <soapenv:Body>
 <sayHello xmlns="http://service.mycode.com/">
    <uname>123456</uname>
 </sayHello>
 </soapenv:Body>
</soapenv:Envelope>
<!-- sayHello是方法名 uname 是参数名 123456 是要传的值 xmlns="http://service.mycode.com/"是后台配置的 targetNamespace = "http://service.mycode.com/"-->
<!-- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <sayHello xmlns="http://service.mycode.com/">
      <uname>青山隐隐水迢迢</uname>
    </sayHello>
  </soap:Body> 
</soap:Envelope> -->

后台代码

import com.mycode.service.NetbarServices;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.el.ELManager;
import javax.xml.ws.Endpoint;

@Configuration
public class CxfConfig {
    @Autowired
    private Bus bus;
    @Autowired
    private NetbarServices netbarServices;

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus,netbarServices);
		 //明确(暴露)该服务的接口地址,防止nginx代理时丢失端口(也可以服务器开通该端口)
//        endpoint.setPublishedEndpointUrl("127.0.0.1:701/webservice/pushProperData?wsdl");
//        endpoint.getInInterceptors().add(new AuthInterceptor());
        endpoint.publish("/NetbarServices");//接口发布在 /NetbarServices 目录下
        return endpoint;
    }
}
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

/**
 * 网吧web services 接口
 * @author xiaojf 2017/7/24 21:35
 */
@WebService// 命名空间,一般是接口的包名倒序
public interface NetbarServices {
    @WebMethod
    String sayHello(@WebParam(name = "uname", targetNamespace = "http://service.mycode.com/") String uname);
}

import javax.jws.WebParam;
import javax.jws.WebService;

import org.springframework.stereotype.Component;

/**
 *  网吧web services 接口实现
 * @author xiaojf 2017/7/24 21:38
 */
@WebService(serviceName = "NetbarServices"//服务名
        ,targetNamespace = "http://service.mycode.com/"//包名倒序,并且和接口定义保持一致
        ,endpointInterface = "com.mycode.service.NetbarServices")//包名
@Component
public class NetbarServicesImpl implements NetbarServices {
    @Override
    public String sayHello(String uname) {
        System.out.println("vdsvfsvdsvdsvdsvdsv");
        return "hello , "+ uname;
    }
}

application.properties

#开发环境
server.port=701
cxf.path=/webservice
<think>好的,用户想了解如何开发Web Service接口程序。首先,我需要明确Web Service的基本概念,然后根据提供的引用资料,整理出开发步骤和注意事项。用户提供的引用中提到了微信小程序与Web Service的通信、C#创建WCF服务以及ASP.NET Web Service的创建和调用,这些都是关键点。 首先,要介绍Web Service的定义和常见技术,比如REST和SOAP,以及微软的WCF框架。然后分步骤讲解开发流程,包括环境搭建、服务创建、接口定义、部署和测试。需要结合引用中的例子,比如使用Visual Studio创建WCF服务,或者ASP.NET的Web Service项目。 同时,注意用户可能对具体的技术选型有疑问,比如何时使用REST或SOAP,WCF的优势在哪里。要确保回答结构清晰,每个步骤都有代码示例或操作指导,比如引用中提到的代码片段和生成WebReference的部分。 另外,用户可能需要了解不同平台下的开发方式,比如微信小程序如何调用Web Service,这里需要提到客户端调用方法,如HTTP请求,并参考引用1中的通信方法。还要注意安全性、数据格式转换等常见问题,以及如何测试服务接口的有效性。 最后,生成相关问题,帮助用户深入理解,比如性能优化、安全机制、不同框架对比等。需要检查引用标记是否正确,比如引用1、2、3对应的内容是否准确,确保回答真实可靠,符合用户的需求。</think>### Web Service接口程序开发教程 Web Service接口开发主要涉及服务端定义接口、客户端调用通信。以下是基于不同技术栈的**开发步骤及核心要点**: --- #### 一、Web Service基础概念 1. **定义** Web Service是通过网络提供标准化接口的应用程序组件,支持跨平台通信,通常基于$HTTP$协议,数据格式为$XML$或$JSON$。 2. **常见技术** - **RESTful API**:基于资源表述的状态转移,轻量级,适合移动端和Web应用。 - **SOAP**:基于XML的消息协议,适合企业级复杂事务[^2]。 - **WCF(Windows Communication Foundation)**:微软框架,支持多种协议(HTTP、TCP等),集成安全性和事务处理。 --- #### 二、开发流程(以C#/ASP.NET为例) ##### 1. **环境搭建** - 安装**Visual Studio**(如2019或更高版本),确保包含**ASP.NET**或**WCF**开发组件[^2][^3]。 ##### 2. **创建Web Service项目** - **ASP.NET Web Service**: ```csharp // 示例:创建简单加法接口 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class MathService : WebService { [WebMethod] public int Add(int a, int b) { return a + b; } } ``` 编译后生成`WSDL`文件,供客户端调用[^3]。 - **WCF Service Application**: 定义服务合同(`IServiceContract`)和数据合同(`DataContract`),支持REST或SOAP绑定[^2]。 ##### 3. **部署与测试** - 本地调试使用IIS Express,生产环境部署到IIS或云服务器。 - 测试工具: - **Postman**:测试RESTful接口。 - **SOAPUI**:验证SOAP服务。 ##### 4. **客户端调用** - **C#调用示例**: ```csharp // 添加Web引用后调用 var service = new MathService(); int result = service.Add(3, 5); ``` - **微信小程序调用**(参考引用[^1]): ```javascript wx.request({ url: 'https://api.example.com/math/add?a=3&b=5', success(res) { console.log(res.data); } }) ``` --- #### 三、关键注意事项 1. **安全性** - 使用$HTTPS$加密通信。 - 身份验证机制(如OAuth 2.0、API密钥)。 2. **性能优化** - 缓存常用数据(如Redis)。 - 异步处理高并发请求。 3. **跨域问题** 配置CORS(跨域资源共享),允许指定域名访问。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HHUFU..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值