12.11 PDFを生成しバッチ印刷するサンプル(WCF)
概要
PDFを生成しバッチ印刷するサンプルプログラムです
ソースサンプル
<biz-Stream_home>/sample/soap_client/dotNET/wcf/WSS_WCF_Sample10.aspx.cs
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Web;
using BizStreamWebApplication.BizStreamServiceReference;
namespace BizStreamWebApplication
{
public partial class WSS_WCF_Sample10 : System.Web.UI.Page
{
// Webサービスサーバのホスト名
const string WSS_HOST_NAME = "wsssrv";
// Webサービスサーバ上のサンプルディレクトリの場所
const string WSS_BIZSTREAM_SAMPLE_DIR = "\\bs\\sample";
// Webサービスのエンドポイントプリフィックス
const string WSS_SERVICE_LOCATION = "http://" + WSS_HOST_NAME + ":8080/axis2/services";
// BASIC認証のユーザ名
const string USER_NAME = @"bizuser1";
// BASIC認証のパスワード
const string PASSWORD = @"bizuser1";
// 監査ロギング用のユーザ定義
const string USER_DEF = "AAA";
// 入力レイアウト定義ファイル名
const string LAYOUT_FILE = WSS_BIZSTREAM_SAMPLE_DIR + "\\xml\\Cloud\\CloudSample1.xml";
// 印刷サーバのホスト名
const string PRINT_HOST_NAME = "prntsrv";
// 印刷サービスのエンドポイントプリフィックス
const string PRINT_SERVICE_LOCATION = "http://" + PRINT_HOST_NAME + ":3000";
// プリンタ名
const string PRINTER_NAME = "Bullzip PDF Printer";
protected void Page_Load(object sender, EventArgs e)
{
// バッチ印刷のストリームに出力を行う
generateOutputDataResponse dataResponse = generate();
// 印刷結果取得のためjobIDを取得
printResult prnResult = dataResponse.printResult;
string jobID = prnResult.jobId;
// バッチ印刷のレスポンスを取得する
// 本サンプルはプリンタの印刷完了を待たないので「印刷待ち」や「印刷中」となる場合があります
queryResult batchResult = getBatchResult(jobID);
printStatus prnStat = batchResult.printStatuses[0];
// ステータス
status stat = prnStat.status;
string result = stat.Value;
string statusCode = stat.code;
// 情報取得日時
string dateTime = prnStat.dateTime;
// プリンタ情報
printer prn = prnStat.printer;
string printerName = prn.name;
string jobName = prn.jobName;
// エラー情報
error err = prnStat.error;
string errCause = err.cause;
string errCode = err.code;
string errDetail = err.details;
// ブラウザに結果を表示
Response.Clear();
Response.ContentType = "text/html;charset=UTF-8";
Response.Write("<HTML><HEAD><TITLE>WSS_WCF_Sample10</TITLE></HEAD><BODY>");
Response.Write("<BR>RESULT = " + result);
Response.Write("<BR>STATUS_CODE = " + statusCode);
Response.Write("<BR>DATE_TIME = " + dateTime);
Response.Write("<BR>PRINTER_NAME = " + printerName);
Response.Write("<BR>JOB_NAME = " + jobName);
Response.Write("<BR>ERROR_CODE = " + errCode);
Response.Write("<BR>ERROR_CAUSE = " + errCause);
Response.Write("<BR>ERROR_DETAILS = " + errDetail);
Response.Write("<BR></BODY></HTML>");
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
private generateOutputDataResponse generate()
{
// クライアントを生成
bizstreamPortTypeClient client =
new bizstreamPortTypeClient("BizstreamSOAP11port",
WSS_SERVICE_LOCATION + "/bizstream?UserDef=" + USER_DEF);
// 認証の設定
BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
elements.Find<HttpTransportBindingElement>().AuthenticationScheme =
System.Net.AuthenticationSchemes.Basic;
client.ClientCredentials.UserName.UserName = USER_NAME;
client.ClientCredentials.UserName.Password = PASSWORD;
// MTOMを有効化
elements.Remove<TextMessageEncodingBindingElement>();
MtomMessageEncodingBindingElement mtom = new MtomMessageEncodingBindingElement();
mtom.ReaderQuotas.MaxStringContentLength = 100000;
elements.Insert(0, mtom);
elements.Find<HttpTransportBindingElement>().KeepAliveEnabled = false;
client.Endpoint.Binding = new CustomBinding(elements);
// リクエストメッセージの作成
generateOutputDataRequest request = new generateOutputDataRequest();
// バッチ印刷の出力を設定
output outPut = new output();
batchPrint batchPrint = new batchPrint();
doPrint doPrint = new doPrint();
printer prn = new printer();
doPrint.url = PRINT_SERVICE_LOCATION;
batchPrint.doPrint = doPrint;
prn.name = PRINTER_NAME; // プリンタ名
prn.jobName = "WSS_WCF_Sample10"; // ジョブ名
prn.numberOfCopy = "1"; // 印刷部数
prn.selectedTray = "AUTO"; // 出力トレイ
prn.fromPage = "1"; // 開始ページ番号
prn.toPage = "-1"; // 終了ページ番号
// prn.password = "password"; // sppファイル暗号化パスワード
// prn.passwordWithEncoded = "cGFzc3dvcmQ="; // エンコード済み暗号化パスワード
prn.doFit = "true"; // 用紙に合わせて印刷
batchPrint.printer = prn;
outPut.Item = batchPrint;
request.output = outPut;
// レイアウト定義を設定
request.layoutData = new layoutDefinition[1];
request.layoutData[0] = new layoutDefinition();
request.layoutData[0].uri = LAYOUT_FILE;
// リクエストを送信
return client.generateOutputData(request);
}
private queryResult getBatchResult(String jobID)
{
// クライアントを生成
bizstreamPortTypeClient client =
new bizstreamPortTypeClient("BizstreamSOAP11port",
WSS_SERVICE_LOCATION + "/bizstream?UserDef=" + USER_DEF);
// 認証の設定
BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
elements.Find<HttpTransportBindingElement>().AuthenticationScheme =
System.Net.AuthenticationSchemes.Basic;
client.ClientCredentials.UserName.UserName = USER_NAME;
client.ClientCredentials.UserName.Password = PASSWORD;
// MTOMを有効化
elements.Remove<TextMessageEncodingBindingElement>();
MtomMessageEncodingBindingElement mtom = new MtomMessageEncodingBindingElement();
mtom.ReaderQuotas.MaxStringContentLength = 100000;
elements.Insert(0, mtom);
elements.Find<HttpTransportBindingElement>().KeepAliveEnabled = false;
client.Endpoint.Binding = new CustomBinding(elements);
// ジョブIDを設定
query qry = new query();
qry.url = PRINT_SERVICE_LOCATION;
string[] array = new string[1];
array[0] = jobID;
qry.jobId = array;
// リクエストを送信
return client.getBatchStatus(qry);
}
}
}
