登陆PO服务器,启动JAVA客户端三步(SAP PO 开发一)
搭建一个WebService接口环境(SAP PO 开发 二)
用SAP PO连通一个WebService接口(SAP PO 开发 三)
ERP系统RFC协议发送端通过PO连通WebService接口(SAP PO 开发四)
我的第一个SAP PROXY ABAP Program(SAP PO 开发五)
SAP PO (Process Orchestration) 中间件接口管理平台(SAP PO 开发六)
C# 调用SAP PO中间件的WebService接口(SAP PO 开发八)
开发工具: VS2017 .net framework4.0
服务方:我们自己建一个WebService接口服务,等待调研。
请求方:Soap UI软件作客户端来调用WS接口。
一、用VS2017建一个WCF的DLL:
新建一个WCF项目,什么都不改动它,用它自带的代码事例就好:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service1”。
// 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 Service1.svc 或 Service1.svc.cs,然后开始调试。
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
自带的事例接收一个整型变量为参数,返回一个字符串结果。
生成这个WCF的DLL,在bin目录里面:
二、作一个winform桌面应用程序为属主,让这个WCF的DLL作为寄生虫在上面工作:
(不想这么恶心?DLL动态链接库不能直接运行,要么放到IIS的web属主容器中,要么放到应用程序的进程容器中)
建一个WINFORM程序:
添加有关于WEBSERVICE 的引用:
在把第一步我们作的WcfService1.dll也引用进来,注意选“复制”:
加几行代码,启动WCF寄生:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.Services;
using System.Windows.Forms;
using System.ServiceModel;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private ServiceHost host = null;
public Form1()
{
InitializeComponent();
try
{
host = new ServiceHost(typeof(WcfService1.Service1));//WcfDemo.Service1 为引用的dll中的服务
host.Open();//启动服务
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
如果WINFORM没有配置文件app.config,需要添加一个:
打开app.config文件,把配置信息拷贝进去,注意改上自己的IP地址:
(<add baseAddress="http://10.18.33.181:8000/"/>)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true"/>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<services>
<!--添加服务-->
<service name="WcfService1.Service1" behaviorConfiguration="CalculatorServiceBehavior">
<!--name 必须与代码中的host实例初始化的服务一样 behaviorConfiguration 行为配置 -->
<host>
<baseAddresses>
<!--添加调用服务地址-->
<add baseAddress="http://10.18.33.181:8000/"/>
</baseAddresses>
</host>
<!--添加契约接口 contract="WcfDemo.IService1" WcfDemo.IService1为契约接口 binding="wsHttpBinding" wsHttpBinding为通过Http调用-->
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
</service>
</services>
<!--定义CalculatorServiceBehavior的行为-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
OK,编译项目,产生exe文件,然后用管理员的权限去执行这个执行程序,8000端口的webservice服务就准备好了。
浏览器访问一下这个接口,http://10.18.33.181:8000/,出来微软为我们做好的接口说明。
用这个: http://10.18.33.181:8000/?wsdl 地址去在SOAPUI上建一个测试demo.
在SOAPUI中双机参数,填上一个值,测试:
我们的环境准备完成,下一步,我们要把SAP PO摆在中间,看看SAP PO怎么去配置。